|
struct node
{int data;
sruct node *next;};
typedef sturct node SLIST;
SLIST *creat_slist()
{int c;/*需要输入的链表数据*/
SLIST *h,*s,*r;/*h头指针
s建立的动态存储单元指针
r链接指针*/
h=(SLIST *)malloc(sizeof(SLIST));
r=h;
scanf(\"%d\",&c);
while(c!=-1)
{s=(SLIST *)malloc(sizeof(SLIST));
s->data=c;
r->next=s;
r=s;
scanf(\"%d\",&c);
}
r->next='\\0';
return h;
}
void printf_slist(SLIST *head)
{SLIST *p;/*指向位置指针*/
p=head->next;
if(p=='\\0') printf(\"linklist is null!\\n\");
else
{printf(\"head\");
do
{printf(\"->%d\",p->data);
p=p->nest;
}while(p!='\\0');
printf(\"the end\\n\");
}
}
void insert_snode(SLIST *head,int x,int y)
{SLIST *s,*p,*q;
s=(SLIST *)malloc(sizeof(SLIST));
s->data=y;
q=head;
p=head->next;
while(p!='\\0'&&p->data!=x)
{q=p;p=p->next;}
s->next=p;
q->next=s;
}
void delete_snode(SLIST*head,int m)
{SLIST *p,*q;
q=head;p=p->next;
while(p!='\\0'&&p->data!=m )
{q=p;p=p->next;
}
if(p->data==m)
q->next=p->next;
}
void screat_snode(SLIST *head,int n)
{SLIST *p;
p=head;
while(p!='\\0'&&p->data!=n)
{p=p->next;}
if(p->data==n)
printf(\"%d\",n);
else
printf(\"not screat snode\\n\");
}
main ()
{SLIST *head;
int x,y,m;/*x定位(要插入数据之后的)数据
y要插入的数据,m要删除的数据*/
scanf(\"%d%d\",x,y);
head= creat_slist();
printf_slist(head);/*链表输出函数*/
screat_snode(head,n);/*链表查找函数*/
insert_snode(hesd,x,y);/*链表插入函数*/
printf_slist(head);
delete_snode(head,m);/*链表删除函数*/
printf_slist(head);
}
哪儿出错了
在tc下无法运行! |
|