| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 678 人关注过本帖, 1 人收藏
标题:请高手帮我看下这个简单的程序问题出在哪里?
取消只看楼主 加入收藏
tjhohai1983
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-4-18
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:0 
请高手帮我看下这个简单的程序问题出在哪里?
#include<iostream.h>
struct node
{
    int data;
    struct node *next;
    struct node *prev;
};
struct node *create()
{
    struct node *p,*q,*head;
    head=0;
    int i;
    cin>>i;
    while(i!=0)
    {
        p=new struct node;
        p->data=i;
        p->next=0;
        if(head==0)
        {
            head=p;
            q=head;
        }
        else
        {
            q->next=p;
            p->prev=q;
            q=p;
        }
        cin>>i;
    }
    return(head);
}
void show(struct node *head)
{
    struct node *p;
    p=head;
    while(p!=0)
    {
        cout<<p->data<<endl;
        p=p->next;
    }
}
struct node *sort(struct node *head)
{
    struct node *p,*q,*r,*t,*headnew=0;
    p=head;
    r=head;
    int max=0;
    while(r!=0)
    {
        p=r;
        max=0;
        while(p!=0)
        {
            if(p->data>max)
            {
                max=p->data;
                q=p;
            }
            p=p->next;
        }
        if(q->prev==0&&q->next!=0)
            head=q->next;
        else if(q->next==0&&q->prev!=0)
           q->prev->next=0;
        else
            q->prev->next=q->next;
            q->prev=0;
            q->next=0;
            if(headnew==0)
            {
                headnew=q;
                t=headnew;
            }
            else
            {
                t->next=q;
                t=q;
                q->prev=t;
            }
            r=head;
    }
    return(headnew);
}
void main()
{
    struct node *head;
    head=create();
    show(head);
    head=sort(head);
    show(head);
}
编译没错误,就是运行的时候出问题了,不能继续运行下去。只能显示没有排序之前的链表的内容。
2010-04-29 11:01
快速回复:请高手帮我看下这个简单的程序问题出在哪里?
数据加载中...
 
   



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

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