| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 829 人关注过本帖
标题:看看这代码哪错了
只看楼主 加入收藏
hhspq2007
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-11-14
收藏
 问题点数:0 回复次数:2 
看看这代码哪错了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define NULL 0
#define LEN sizeof(node)
typedef int elemtype;
struct node
{
    elemtype data;
    struct node*next;
};
struct node*Createlist()
{
    node*head=NULL,*p=NULL,*r=NULL;
    head=(node*)malloc(LEN);
    r=head;
    cout<<"请输入链表的长度:"<<endl;
    int n,temp;
    cin>>n;
    cout<<"请按顺序输入链表元素:"<<endl;
    for(int i=0;i<n;i++)
    {
        p=(node*)malloc(LEN);
        cin>>temp;
        p->data=temp;
        r->next=p->next;
        r=p;
    }
    return (head);
}
void Traverser(struct node*head)
{
    if(head->next==NULL)
    {
        cout<<"Error!"<<endl;
        exit(1);
    }
    else
    {
        node*r=head->next;
        while(r!=NULL)
        {
            cout<<r->data<<" ";
            r=r->next;
        }
    }
}
int IsEmpty(struct node*head)
{
    if(head->next==NULL)
        return 1;
    else
        return 0;
}
void Mergelist(node*La,node*Lb,node*Lc)
{
    node*pa=NULL,*pb=NULL,*pc=NULL;
    Lc=pc=La;
    while(pa&&pb)
    {
        if(pa->data<=pb->data)
        {
            pc->next=pa;
            pc=pa;
            pa=pa->next;
        }
        else
        {
            pc->next=pb;
            pc=pb;
            pb=pb->next;
        }
    }
        pc->next=pa?pa:pb;
        free(Lb);
}
void main()
{
    struct node*La=NULL,*Lb=NULL,*Lc=NULL,*p;
    La=Createlist();
    Lb=Createlist();
    Mergelist(La,Lb,Lc);
    p=Lc->next;
    if(p==NULL)
    {
        cout<<"biao wei kong"<<endl;
    }
    else
    {
        while(p!=NULL)
        {
            cout<<p->data<<" ";
            p=p->next;
        }
    }
    
}
大家看下,调试没错,运行有问题。。。急啊
搜索更多相关主题的帖子: 代码 
2007-12-15 00:16
zxc1998
Rank: 1
等 级:新手上路
威 望:1
帖 子:133
专家分:0
注 册:2007-3-21
收藏
得分:0 
创建链表时,最后一个节点没有终止,赋值NULL。
2007-12-16 09:19
柒兲
Rank: 1
等 级:新手上路
威 望:1
帖 子:126
专家分:0
注 册:2007-9-26
收藏
得分:0 
你想实面什么功能`?

2007-12-16 12:30
快速回复:看看这代码哪错了
数据加载中...
 
   



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

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