全文预览

线性表及多项式作

上传者:火锅鸡 |  格式:doc  |  页数:24 |  大小:110KB

文档介绍
);q->element=x;q->link=p->link;p->link=q;L->n++;returnOK;}单链表的删除(Delate.c):statusDelete(headerList*L,inti){intj;Node*p,*q;if(!L->n)returnERROR;if(i<0||i>L->n-1)returnERROR;q=L->head;for(j=0;j<i;j++)q=q->link;p=q->link;//p指向aiq->link=p->link;//从单链表中删除p所指向的结点free(p);//释放p所指结点的存储空间L->n--;returnOK;}单链表的输出(Output.c):statusOutput(headerListL){Node*p;if(!L.n)//判断顺序表是否为空returnERROR;p=L.head->link;while(p){printf("%d",p->element);p=p->link;}returnOK;}单链表的析构(Destroy.c):voidDestroy(headerList*L){Node*p;while(L->head){p=L->head->link;free(L->head);L->head=p;}}测试所用主函数(main.c):voidmain(){inti;intx;headerListlist;Init(&list);//对线性表初始化for(i=0;i<9;i++)Insert(&list,i-1,i);//线性表中插入新元素printf("thelinklistis:");Output(list);Delete(&list,0);printf("\nthelinklistis:");Output(list);Nizhi(&list);printf("\n逆置后:\n");

收藏

分享

举报
下载此文档