标签:
今天比较忙 晚上回来匆匆打了部分 明天继续 函数内注释都是按自己的理解打的
1 #include "stdio.h" 2 #include "string.h" 3 typedef struct Node 4 { 5 DATA date; 6 struct Node *next; 7 }ChainListType; 8 9 ChainListType *ChinaListAddEnd(ChainListType *head,DATA data); 10 //添加节点到链表末尾 11 ChainListType *ChinaListAddFirst(ChainListType *head,DATA data); 12 //添加节点到链表首部 13 ChainListType *ChinaListFind(ChainListType *head,char *key); 14 //按关键字在链表中查找内容 15 ChainListType *ChinaListInsert(ChainListType *head,char *findkey,DATA data); 16 //插入节点到链表制定位置 17 int ChinaListDelete(ChainListType *head,char *key); 18 //删除指定关键字的字节 19 int ChinaListLength(ChainListType *head); 20 //获取链表节点数量 21 22 23 ChainListType *ChinaListAddEnd(ChainListType *head,DATA data) 24 { 25 ChainListType *node,*h; 26 if(!node=(ChainListType *)malloc(sizeof(ChainListType))) 27 { 28 printf("为保存节点数据申请内存失败!"); 29 return NULL; 30 } 31 node->data=data; 32 node->next=NULL; //*node为表尾 33 34 if(head==NULL) //如果第一个节点为NULL 35 { 36 head=node; //直接把数据添加 37 return head; 38 } 39 h=head; //把传入的头指针赋给一个新指针 40 while(h->next!=NULL) 41 h=h->next; //让h指向最后一个节点 42 h->next=node; //把node赋值给最后一个节点 43 return head; 44 }
标签:
原文地址:http://www.cnblogs.com/threezj/p/4430450.html