首页 > 其他 > 详细

数据结构复习之链表

时间:2014-03-04 13:05:49      阅读:429      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 struct node *create(int n)//顺序建立链表  
 2 {  
 3     int i,num;  
 4     struct node *head,*tail,*p;  
 5     head = (struct node*)malloc(sizeof(struct node));  
 6     head -> next = NULL;  
 7     tail = head;  
 8     for(i = 0;i < n;i ++)  
 9     {  
10         scanf("%d",&num);  
11         p = (struct node*)malloc(sizeof(struct node));  
12         p -> data = num;  
13         p -> next = NULL;  
14         tail -> next = p;  
15         tail = p;  
16     }  
17     return head;  
18 }  
19 struct node *create(int n)  //逆序
20 {  
21     struct node *head,*tail,*p;  
22     int i,num;  
23     head = (struct node*)malloc(sizeof(struct node));  
24     head -> next = NULL;  
25     tail = NULL;  
26     for(i = 0;i < n;i ++)  
27     {  
28         scanf("%d",&num);  
29         p = (struct node*)malloc(sizeof(struct node));  
30         p -> data = num;  
31         p -> next = tail;  
32         tail = p;  
33     }  
34     head -> next = tail;  
35     return head;  
36 }  
37 struct node *reverse(struct node *head)//反转
38 {
39     struct node *s,*p,*tail;
40     s = head -> next;
41     tail = NULL;
42     while(s)
43     {
44         p = s -> next;
45         s -> next = tail;
46         tail = s;
47         s = p;
48     }
49     head -> next = tail;
50     return head;
51 }
52 void show(struct node *head)//显示
53 {
54     int flag = 1;
55     struct node *s;
56     s = head -> next;
57     while(s)
58     {
59         if(flag) flag = 0;
60         else printf(" ");
61         printf("%d",s->data);
62         s = s -> next;
63     }
64 }
bubuko.com,布布扣

数据结构复习之链表,布布扣,bubuko.com

数据结构复习之链表

原文:http://www.cnblogs.com/local8080/p/3579217.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!