码迷,mamicode.com
首页 > 其他好文 > 详细

操作单向链表

时间:2015-04-15 23:00:05      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

今天比较忙   晚上回来匆匆打了部分  明天继续  函数内注释都是按自己的理解打的

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!