当前位置:中国飞客联盟文章中心编程学习C 语言 → 链表的c语言实现(五)

链表的c语言实现(五)

减小字体 增大字体 作者:佚名  来源:转载  发布时间:2007-8-22 22:37:45
3、删除假如我们已经知道了要删除的结点p的位置,那么要删除p结点时只要令p结点的前驱结点的链域由存储p结点的地址该为存储p的后继结点的地址,并回收p结点即可。以下便是应用删除算法的实例:#include <stdio.h>#include <malloc.h>#include <string.h>#define N 10typedef struct node{char name[20];struct node *link;}stud;stud * creat(int n) /*建立新的链表的函数*/{stud *p,*h,*s;int i;if((h=(stud *)malloc(sizeof(stud)))==NULL){printf("不能分配内存空间!");exit(0);}h->name[0]='\0';h->link=NULL;p=h;for(i=0;i<n;i++){if((s= (stud *) malloc(sizeof(stud)))==NULL)