int init(LinkList *L) { *L=(LNode *)malloc(sizeof(LNode)). if(!L) exit(ERROR). (*L)->next=NULL. return OK. }/*init */
int ListLength(LinkList L) { int j=0. while (L->next) { L=L->next. j . } return j. }
int GetElem(LinkList L,int i,ElemType *e) { LinkList p. int j. p=L->next.j=1. while(p&.&.j p=p->next. j. } if(!p||j>1) return ERROR. *e=p->data. return OK. }
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)<=0) return 1. else return 0. } int LocateElem(LinkList La,ElemType e,int type) { int i. LinkList p. p=La. switch (type) { case EQUAL: while(p->next) { p=p->next. if(EqualList(&.p->data,&.e)) return 1. } return 0. break. default: break. } return 0. }
int printlist(LinkList L) { int i. LinkList p. p=L. printf("name stuno age score\n"). while(p->next) { p=p->next. printf("%-10s %s\t%d\t%d\n", p->data.name, p->data.stuno, p->data.age, p->data.score). } printf("\n"). }
int ListInsert(LinkList L,int i,ElemType e) { LinkList p,s. int j. p=L.j=0. while(p&.&.j { p=p->next. j. } if(!p||j>i-1) return ERROR. s=(LinkList)malloc(sizeof(LNode)). s->data=e. s->next=p->next. p->next=s. return OK. }/*ListInsert Before i */
main() { struct STU e. LinkList La,Lb,Lc.
clrscr().
printf("\n\n-------------------List Demo is running...----------------\n\n"). printf("First is InsertList function.\n"). init(&.La).