c语言链表怎么删除头节点,删除单链表的头结点要怎么做?

02d97a65051cf8520a3a78e37bbae58a.png

2006-11-01

设计一个算法,求出线性表中数据域的值为x的结点的序号。序号从表头算起,若链表中无此结点则序号为零.

必须是调试后的程序.

#include#include#include#define ERROR 0#define OK 1#define EQUAL 1#define OVERFLOW -1#define LIST_INIT_SIZE 100#define LISTINCREMENT 10struct STU{char name[20];char stuno[10];int age;int score;}stu[50];typedef struct STU ElemType;struct LIST{ElemType *elem;int length;int listsi...全部

#include#include#include#define ERROR 0#define OK 1#define EQUAL 1#define OVERFLOW -1#define LIST_INIT_SIZE 100#define LISTINCREMENT 10struct STU{ char name[20]; char stuno[10]; int age; int score;}stu[50];typedef struct STU ElemType;struct LIST{ ElemType *elem; int length; int listsize;};typedef struct LIST List;int init(List *L){ L->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType)); if(!L->elem) exit(OVERFLOW); L->length=0; L->listsize=LIST_INIT_SIZE; return OK;}/*init */int ListLength(List *L){ return L->length;}void GetElem(List L,int i,ElemType *e){ *e=L。

elem[i];}int EqualList(ElemType *e1,ElemType *e2){ if (strcmp(e1->name,e2->name)==0) return 1; else return 0;}int Less_EqualList(ElemType *e1,ElemType *e2){ if (strcmp(e1->name,e2->name)length;i++) if(EqualList(&La->elem[i],&e)) return 1;break; default:break; } return 0;}void MergeList(List *La,List *Lb,List *Lc){ ElemType *pa,*pb,*pc,*pa_last,*pb_last; pa=La->elem;pb=Lb->elem; Lc->listsize = Lc->length = La->length + Lb->length; pc = Lc->elem = (ElemType *)malloc(Lc->listsize * sizeof(ElemType)); if(!Lc->elem) exit(OVERFLOW); pa_last = La->elem + La->length - 1; pb_last = Lb->elem + Lb->length - 1; while(paL->length+1) return ERROR; q=&(L->elem[i-1]); for(p=&L->elem[L->length-1];p>=q;--p) *(p+1)=*p; *q=e; ++L->length; return OK;}/*ListInsert Before i */main(){ struct STU e; List La,Lb,Lc; clrscr(); printf("\n\n-------------------List Demo is running。

。。----------------\n\n"); printf("First is InsertList function。\n"); init(&La); strcpy( ,"stu1"); strcpy( uno,"100001"); e=80; ore=1000; ListInsert(&La,1,e); strcpy( ,"stu3"); strcpy( uno,"100002"); e=80; ore=1000; ListInsert(&La,2,e); printlist(La); printf("List A length now is %d。

\n\n",La。length); getch(); strcpy( ,"stu5"); strcpy( uno,"100003"); e=80; ore=1000; ListInsert(&La,3,e); printlist(La); printf("List A length now is %d。

\n\n",La。length); getch(); init(&Lb); strcpy( ,"stu2"); strcpy( uno,"100001"); e=80; ore=1000; ListInsert(&Lb,1,e); strcpy( ,"stu4"); strcpy( uno,"100002"); e=80; ore=1000; ListInsert(&Lb,2,e); strcpy( ,"stu6"); strcpy( uno,"100001"); e=80; ore=1000; ListInsert(&Lb,3,e); printlist(Lb); printf("List B length now is %d。

\n\n",Lb。length); getch(); MergeList(&La,&Lb,&Lc); printlist(Lc); getch(); printf("Second is UnionList function。

\n"); printf("Now union List A and List B。。。。。\n"); UnionList(&La,&Lb); printlist(La); printf("List A length now is %d。

\n\n",La。length); getch(); printf("\n\n\n\n\n\nWelcome to visit !\n\n\n\n\n\n\n");}。

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值