链表元素的逆序输出

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 #define ElemType int 
 5 #define N 5                                      //定义链表的结点数目
 6 typedef struct Node
 7 {
 8     ElemType data; 
 9     struct Node *next;
10 }Node;
11 typedef struct Node *LinkList;
12 
13 
14 
15 Node* CreatList(Node *La,int n)
16 {
17     int i;
18     struct Node *s;
19     La = (LinkList)malloc(sizeof(Node));
20     La->next = NULL;                         //初始化
21     for(i = 1;i <= n;i++)
22     {
23         s = (LinkList)malloc(sizeof(Node));
24         scanf("%d",&(s->data));
25         s->next = La->next;
26         La->next = s;                        //利用头插法构造链表
27     }
28         
29     return La;
30 }
31 //函数值调换
32 int  SortList(Node *Lb,int n) 
33 {
34     int i;
35     int a[n];
36     for(i = 0;i < n;i++)
37     {
38         Lb = Lb->next;
39         a[i] = Lb->data;    
40     }
41     for(i = n-1;i >= 0;i--)
42     {
43         printf("%3d",a[i]);
44     }
45     return 1;
46 }
47 int main(int argc, char *argv[])
48 
49 {
50     int i;
51     struct Node *L,*p;
52     L = CreatList(L,N);
53     p = L;
54     printf("the data is:\n");
55     for(i = 1;i <= N;i++)
56     {
57         p = p->next;
58         printf("%3d",p->data);
59     }
60     printf("\nAfter sorted,the data is\n");
61     SortList(L,N);
62     getch();
63 //    system("pause"); 
64     return 0;
65 }

 

posted on 2014-12-11 21:39 BeatificDevin 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/devinblog/p/4158570.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值