CPP如下
#include
#include
#include"LinkList.h"
typedef int ElemType
int main(void)
{
LNode H,*p;
p=&H;
InitList(p);
while(getc()!='#'){
cindate;
p=p->next
}
p->next=NULL;
coutnext;
}
return i;
}
int EmptyList (LNode *H)
{
for(int i=0;inext;
}
return 1;
}
ElemType GetList (LNode *H, int pos)
{
if(posnext;
return H->date;
}
void TraverseList(LNode *H)
{
while(H!=NULL){
coutdatenext;
}
}
int InsertList ( LNode *&H, ElemType item, int pos)
{
if(posdate=item;
LNode *cp=H;
LNode *ap=NUll;
if(pos==0){
while(cp!=NULL){
if(itemdate)break;
else{
ap=cp;
cp=cp->next;
}
}
}
else if(pos==-1)
while(cp!=NULL)
{
ap=cp;cp=cp->next;
}
else{
int i=0;
while(cp!=NULL){
i++;
if(i==pos)break;
else{
ap=cp;
cp=cp->next;
}
}
if(cp==NULL&&i+1next=H;
H=newtpr;
}
else
{newptr->next=cp;
ap->next=newptr;
}
return 1;
}
int DeleteList ( LNode *&H, ElemType &item, int pos)
{
if(posdate=item;
LNode *cp=H;
LNode *ap=NUll;
if(pos==0){
while(cp!=NULL){
if(item==cp->date)break;
else{
ap=cp;
cp=cp->next;
}
}
if(cp==NULL){
coutnext!=NULL)
{
ap=cp;cp=cp->next;
}
else{
int i=0;
while(cp!=NULL){
i++;
if(i==pos)break;
else{
ap=cp;
cp=cp->next;
}
}
if(cp==NULL){
coutnext;
else ap->next=cp->next;
delete cp;
return 1;
}错误太多了 帮忙改下啊!函数依次是 初始化单链表 清除单链表 求单链表长度 判断是否为空表 遍历单链表 插 删
|