| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1319 人关注过本帖
标题:链表合并问题
只看楼主 加入收藏
ヤ吵吵o
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-10-14
收藏
 问题点数:0 回复次数:1 
链表合并问题
``能帮忙找下错误并修改过来么`???
 #include"stdio.h"
#include"stdlib.h"
#include<iostream.h>
typedef int datatype;
typedef struct node{
    datatype data;
    struct node *next;
}lnode,*pointer;
pointer initlist(){
    pointer l=new lnode();
    l->next=NULL;
    return l;
    }
pointer create_list(){
    pointer head,p,q;
    datatype x;
    head=(pointer)malloc(sizeof(lnode));
    p=head;
    cout<<"请从小到大输入链表的元素,输入0则结束:\n";
    cin>>x;
    while(x!=0)
    {
        q=(pointer)malloc(sizeof(lnode));
        q->data=x;
        p->next=q; p=q;
        cout<<"请输入下一个数:\n";
        cin>>x;
}
    p->next=NULL;
    return head;
}

void print_list(pointer head){
    pointer p;
    p=head->next;
    while(p!=NULL) {
        cout<<p->data<<"\t"; p=p->next;
 }
    cout<<endl;
}

pointer union_list(pointer p,pointer q) {
    if(p->next==NULL||q->next==NULL||p==NULL||q==NULL)
        return 0; pointer r1,r2,ptr;
    ptr = p;
    r1 = p->next;
    r2 = q->next;
    ptr->next = NULL;
    q->next =NULL;
   
    while(r1 != NULL && r2 != NULL)
    { if(r1->data>r2->data)
    { ptr->next = r2;
    ptr = ptr->next;
    r2 = r2->next;
    ptr->next = NULL;
 } else if(r1->data<r2->data)
    {
     ptr->next = r1;
 ptr = ptr->next;
 r1 = r1->next;
 ptr->next=NULL;
 } else
 {
     ptr->next = r1;
 ptr = ptr->next;
 r1 = r1 ->next;
 r2 = r2 ->next;
 ptr->next = NULL;
}
}
    if(r1 != NULL)
        ptr->next = r1;
    if(r2 !=NULL)
        ptr->next = r2;
    return p;
}

void main() {
    pointer Alist,Blist;
    cout<<"请输入链表A的元素:\n"; Alist=create_list();
    print_list(Alist);
    cout<<"\n请输入链表B的元素:\n"; Blist=create_list();
    print_list(Blist);
    cout<<"合并后的链表:"<<endl;
    Alist = union_list(Alist,Blist);
    print_list(Alist);
    cout<<endl;
}
搜索更多相关主题的帖子: 链表 
2009-10-14 15:35
ヤ吵吵o
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-10-14
收藏
得分:0 
--------------------Configuration: myjob - Win32 Debug--------------------
Compiling...
myjob.c
E:\myjob.c(10) : error C2065: 'new' : undeclared identifier
E:\myjob.c(10) : warning C4047: 'initializing' : 'struct node *' differs in levels of indirection from 'int '
E:\myjob.c(10) : error C2146: syntax error : missing ';' before identifier 'lnode'
E:\myjob.c(10) : error C2063: 'lnode' : not a function
E:\myjob.c(19) : error C2065: 'cout' : undeclared identifier
E:\myjob.c(19) : error C2297: '<<' : illegal, right operand has type 'char [39]'
E:\myjob.c(20) : error C2065: 'cin' : undeclared identifier
E:\myjob.c(20) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
E:\myjob.c(26) : error C2297: '<<' : illegal, right operand has type 'char [17]'
E:\myjob.c(27) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
E:\myjob.c(37) : error C2297: '<<' : illegal, right operand has type 'char [2]'
E:\myjob.c(39) : error C2065: 'endl' : undeclared identifier
E:\myjob.c(39) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
E:\myjob.c(44) : error C2275: 'pointer' : illegal use of this type as an expression
        E:\myjob.c(8) : see declaration of 'pointer'
E:\myjob.c(44) : error C2146: syntax error : missing ';' before identifier 'r1'
E:\myjob.c(44) : error C2065: 'r1' : undeclared identifier
E:\myjob.c(44) : error C2065: 'r2' : undeclared identifier
E:\myjob.c(44) : error C2065: 'ptr' : undeclared identifier
E:\myjob.c(45) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct node *'
E:\myjob.c(46) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct node *'
E:\myjob.c(47) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct node *'
E:\myjob.c(48) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(51) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *'
E:\myjob.c(51) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *'
E:\myjob.c(52) : error C2223: left of '->data' must point to struct/union
E:\myjob.c(52) : error C2223: left of '->data' must point to struct/union
E:\myjob.c(53) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(54) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(55) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(56) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(57) : error C2223: left of '->data' must point to struct/union
E:\myjob.c(57) : error C2223: left of '->data' must point to struct/union
E:\myjob.c(59) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(60) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(61) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(62) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(65) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(66) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(67) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(68) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(69) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(72) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *'
E:\myjob.c(73) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(74) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *'
E:\myjob.c(75) : error C2223: left of '->next' must point to struct/union
E:\myjob.c(81) : error C2297: '<<' : illegal, right operand has type 'char [20]'
E:\myjob.c(83) : error C2297: '<<' : illegal, right operand has type 'char [21]'
E:\myjob.c(85) : error C2297: '<<' : illegal, right operand has type 'char [14]'
E:\myjob.c(88) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
执行 cl.exe 时出错.
 
myjob.exe - 1 error(s), 0 warning(s)


这是组建时给出的错误分析``不懂``
2009-10-14 15:37
快速回复:链表合并问题
数据加载中...
 
   



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

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