| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1395 人关注过本帖
标题:链表的逆置大问题
只看楼主 加入收藏
浅暗花璃
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2016-3-31
结帖率:77.78%
收藏
 问题点数:0 回复次数:0 
链表的逆置大问题
#include <stdio.h>
#include <stdlib.h>
struct student {
    int old;
    struct student *next;
};

struct student *create();
 struct student *f(struct student *head);
void output(struct student *head);

void main()
{

    struct student *head;
    head=create();
     head=f(head);
    output(head);
}
struct student *create()
{
    struct student *head,*p,*q;
    int n,i=0;
    head=(struct student *)malloc(sizeof(struct student));
   
    p=(struct student *)malloc(sizeof(struct student));
    printf("plase input 节点数:");
    scanf("%d",&n);
    printf("plase input 年龄:");
    scanf("%d",&p->old);
    head->next=p;
    p->next=NULL;
    while(1)
    {
        if(i==n)
            break;
            i++;
        q=(struct student *)malloc(sizeof(struct student));
        if(i<n){

            printf("plase input 年龄:");
            scanf("%d",&q->old);
            p->next=q;
            
            p=q;
        }
        
    }
    free(q);
   p->next=NULL;
    return(head);
}
  struct student *f(struct student *head)
{
    struct student *p,*q,*s;
    int i=0;
  
    p=head->next;
    q=p->next;
    s=q->next;
    while(s!=NULL)
    {
        q->next=p;
        p=q;
        q=s;
        s=s->next;
        
    }
   
   
    q->next=p;
    head->next=q;
    p->next->next=NULL;

    return(head);
   
}
   



void output(struct student *head)
{
    struct student *p=head->next ;
    while(p!=NULL)
    {

        printf("%d\n",p->old);
        p=p->next;
    }
}
为什么3个节点是好的,多了就不行了




搜索更多相关主题的帖子: include create 
2016-06-10 11:43
快速回复:链表的逆置大问题
数据加载中...
 
   



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

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