1、.数据结构单链表及插入删除C语言#include#includetypedef struct LinkLodeint data;struct LinkLode* link;LinkLode;int length;void show(LinkLode* first)first=first-link;while(first-link!=NULL)printf(%d ,first-data);first=first-link;printf(%dn,first-data);LinkLode* newLode(int data)LinkLode *newLode;newLode=(LinkLode *)
2、malloc(sizeof(LinkLode);newLode-data=data;newLode-link=NULL;return newLode;void createList(LinkLode* first)LinkLode*s1,*s2;int i=2;s2=newLode(1);first-link=s2;s1=s2;for(;ilink=s2;s1=s2;length=10;s1=first-link;while(s1-link!=NULL)printf(%d ,s1-data);s1=s1-link;printf(%dn,s1-data);void intList(int i,i
3、nt data,LinkLode* first)LinkLode *s1=first,*s2;int i2=0;s2=newLode(data);if(i=0&i=length)while(i2link;i2+;s2-link=s1-link;s1-link=s2;length+;printf(插入成功n);show(first);elseprintf(插入失败n);void delList(int i,LinkLode* first)LinkLode* s2=first,*s1;int i1=0;if(i0&i=length)while(i1link;i1+;printf(删除的数为:%d,
4、地址为%pn,s2-data,s2);s1-link=s2-link;free(s2);length-;show(first);elseprintf(删除失败n);int main()LinkLode* first;char c1=NULL,c2;int i,data;first = (LinkLode *)malloc(sizeof(LinkLode);first-data=-10;first-link=NULL;createList(first);while(c1!=s)printf(插入请输入i,删除输入d,停止输入sn);scanf(%c,&c1);if(c1=i)printf(请输入插入的数据和插入在第几个数后面,以空格隔开n);scanf(%d%d,&data,&i);intList(i,data,first);c2=getchar();if(c1=d)printf(请输入删除第几个数据n);scanf(%d,&i);delList(i,first);c2=getchar();return 0;精选范本