| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 262 人关注过本帖
标题:链表倒置,求解答 为什么打印出一个0呢。。还有 第二个打印打不出来啊。 ...
只看楼主 加入收藏
lyl59840
Rank: 2
等 级:论坛游民
帖 子:25
专家分:22
注 册:2011-12-14
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
链表倒置,求解答 为什么打印出一个0呢。。还有 第二个打印打不出来啊。。。
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>


typedef struct Lnode{
    int data;
    struct  Lnode *next;
           }*LIST;


LIST CreateList(int n)
{
    int a,i;
    LIST p,q,head;
    head=p=(LIST)malloc(sizeof(LIST));
    p->data = 0;
    for(i=0;i<n;i++)
    {
      q=(LIST) malloc (sizeof(LIST));
      printf("please input the data:\n");
      scanf("%d",&a);
      q->data = a;
      p->next = q;
    }
    return head;
}
void PrintList(LIST head)
{
    LIST p;
    printf("链表当前数据:\n");
    p=head;
    while(p->next!=NULL)
    {
        printf("%d\n",p->data);
        p=p->next;
    }
}
LIST ReverseList(LIST head)
{
    LIST q,p,n;
    if(head=NULL)
        return NULL;
    p=head->next;
    q=p->next;
         while(q)
         {
                 n=q->next;
                 q->next=p;
                 p=q;
                 q=n;
          }
         head->next->next=NULL;
}
void main()
{
    LIST head,afhead;
    int n;
    printf("please  input the nunber of your data:");
    scanf("%d",&n);
    head=CreateList(n);
    PrintList(head);
    afhead=ReverseList(head);
    PrintList(afhead);
}
搜索更多相关主题的帖子: 打印 next include please return 
2012-03-25 11:28
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:10 
调试

                                         
===========深入<----------------->浅出============
2012-03-25 12:43
快速回复:链表倒置,求解答 为什么打印出一个0呢。。还有 第二个打印打不出来 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014792 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved