标题:帮看下这代码
取消只看楼主
hhspq2007
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-11-14
 问题点数:0 回复次数:1 
帮看下这代码
#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;
        }
    }
    
}
哪一位大虾帮我看下,为什么就是不能实行!!在下在这谢谢各位啦!!急用~~
搜索更多相关主题的帖子: node NULL int temp 链表 
2007-12-14 22:55
hhspq2007
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-11-14
得分:0 
真可以了,谢谢楼上的,呵呵
2007-12-18 12:06



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




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

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