#includestdio.h#includestdlib.h#defineN8typedefintElemType;typedefstructnode{ElemTypedata;structnode*next;}LNode,*Linklist;voidCreateList_L(Linklists,intn){s-next=NULL;//createheadnodeLinklistp;inti;for(i=n;i0;--i){p=(Linklist)malloc(sizeof(LNode));//createnewnodep-data=i;p-next=s-next;s-next=p;//inserttoheadofSLL}}voidinsert(Linklists,inti,ElemTypedat){intj=0;Linklistp=s,q;while(pji-1){p=p-next;j++;}q=(Linklist)malloc(sizeof(LNode));q-data=dat;q-next=p-next;p-next=q;}voiddel(Linklists,inti){Linklistp=s;intj=0;while(p-nextji-1){p=p-next;j++;}p-next=p-next-next;}voidprint(Linklistp){while(p-next!=NULL){printf("%d",p-next-data);p=p-next;}printf("\n");}intmain(){intindex,zhi;Linklists;s=(Linklist)malloc(sizeof(LNode));CreateList_L(s,N);printf("原链表数据为:\n");print(s);printf("插入的元素值及其位置下标,用逗号分隔:\n");scanf("%d,%d",zhi,index);insert(s,index,zhi);print(s);printf("删除元素下标:\n");scanf("%d",index);del(s,index);printf("最终输出结果为:\n");print(s);return0;}预览时标签不可点收录于话题#个上一篇下一篇