标题:这个程序哪儿出错,或者还应该改进哪儿
取消只看楼主
l376365333
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-8-2
结帖率:100%
 问题点数:0 回复次数:1 
这个程序哪儿出错,或者还应该改进哪儿
#include<stdio.h>
#include<malloc.h>
typedef struct linka
{
    int data;
    struct linka *next;
}link;
void reverse(link *&head)
{
    if(head==NULL)return;
    linka *pre,*cur,*ne;
    pre=head;
    cur=head->next;
    while(cur)
    {
        ne=cur->next;
        cur->next=pre;
        pre=cur;
        cur=ne;
    }
    head->next=NULL;
    head=pre;
    while(head)
    {
        printf("=%d=",head->data );
        head=head->next ;
    }
}
void main(void)
{
    link *p,*q;
    link *head=(link *)malloc(sizeof(link));
    p=head;
    for(int i=0;i<10;i++)
    {
        p->data =i+1;
        q=(link *)malloc(sizeof(link));
        p->next =q;
        p=q;
    }
    p->next =NULL;
    reverse(head);
   
}
搜索更多相关主题的帖子: 改进 
2010-12-01 18:52
l376365333
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-8-2
得分:0 
#include<stdio.h>
#include<malloc.h>
typedef struct linka
{
    int data;
    struct linka *next;
}link;
void reverse(link *head)
{
    if(head==NULL)return;
    linka *pre,*cur,*ne;
    pre=head;
    cur=head->next;
    while(cur)
    {
        ne=cur->next;
        cur->next=pre;
        pre=cur;
        cur=ne;
    }
    head->next=NULL;
    head=pre;
    while(head)
    {
        printf("=%d=",head->data );
        head=head->next ;
    }
}
void main(void)
{
    link *p,*q;
    link *head=(link *)malloc(sizeof(link));
    p=head;
    for(int i=0;i<10;i++)
    {
        p->data =i+1;
        q=(link *)malloc(sizeof(link));
        p->next =q;
        p=q;
    }
    p->next =NULL;
    reverse(head);
   
}
上边那个有点错
2010-12-01 19:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-327548-1-1.html




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

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