void main(void) { TYPE *head=NULL,*pnum=NULL; int n=3,num; /* 创建一个含 n 个节点的链表 */ printf("input number of node:"); head=creatlink(n); printlink(head); /* 删除链表中值为 num 的节点 */ printf("Input the deleted number:"); scanf("%d",&num); head=deletelink(head,num); printlink(head); /* 在链表中插入一个节点 */ printf("Insert a record\n"); pnum=(TYPE *)malloc(LEN); if(pnum==NULL) printf("Pointer is NULL--memory alloc fail!"); printf("Input the inserted number:"); scanf("%d",&pnum->num); printf("Input the inserted age:"); scanf("%d",&pnum->age); head=insertlink(head,pnum); printlink( head ); /* 销毁链表, 释放动态分配的内存 */ destroylink( head ); }
void main() { struct student *creatlink(); void printlink(struct student *head); void searchid(struct student *head,int m); struct student *insertnode(struct student *head,struct student *stud); struct student *deletenode(struct student *head,int m); struct student *sortid(struct student *head); void deletelink(struct student *head); struct student *head,*stu; int m; head=creatlink(); printlink(head); printf("input the student id you want\n"); scanf("%d",&m); searchid(head,m); printf("\n\nnow it's going to sort it\n\n"); sortid(head); printlink(head); printf("then insert a student record\n "); stu=(struct student *)malloc(LEN); printf("intput the student's id\n"); scanf("%d",&stu->num); printf("input the student's name\n"); scanf("%s",stu->name); printf("input the student's score\n"); scanf("%f",&stu->score); insertnode(head,stu); printlink(head); printf("now input the student you want to delete\n"); scanf("%d",&m); deletenode(head,m); printlink(head); deletelink(head); }