| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 500 人关注过本帖
标题:写两个有顺序的链表并合并
只看楼主 加入收藏
wxh525123
Rank: 2
等 级:论坛游民
帖 子:38
专家分:37
注 册:2010-4-18
结帖率:100%
收藏
已结贴  问题点数:30 回复次数:3 
写两个有顺序的链表并合并
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
struct student
{
    long num;
    int score;
    struct student *next;
    };
struct student listA,listB;
int n,sum=0;
main()
{
    struct student *creat();
    struct student *insert(struct student *,struct student *);
    void print(struct student *);
    struct student *ahead,*bhead,*abh;
    printf("input listA:\n");
    ahead=creat();
    sum=sum+n;
    printf("input listB:\n");
    bhead=creat();
    sum=sum+n;
    abh=insert(ahead,bhead);
    print(abh);
    getch();
    }
struct student *creat()
{
    struct student *p1,*p2,*head;
    n=0;
    p1=p2=(struct student *)malloc(LEN);
    printf("input number&scores of student:\n");
    printf("if number is 0,stop inputing.\n");
    scanf("%ld%d",&p1->num,&p1->score);
    head=NULL;
    while(p1->num!=0)
    {
        n++;
        if(n==1)
            head=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct student *)malloc(LEN);
        scanf("%ld%d",&p1->num,&p1->score);
        }
    p2->next=NULL;
    return head;
    }
void print(struct student *head)
{
    struct student *p;
    printf("\nThere are %d records:\n",sum);
    p=head;
    if(p!=NULL)
        do{
            printf("%ld %d\n",p->num,p->score);
            p=p->next;
            }while(p!=NULL);
    }
struct student *insert(struct student *ah,struct student *bh)
{
    struct student *pa1,*pa2,*pb1,*pb2;
    pa2=pb1=ah;
    pb2=pb1=bh;
    do{
        while((pb1->num>pa1->num)&&(pa1->next!=NULL))
        {
            pa2=pa1;
            pa1=pa1->next;
            }             /*如果pb1比pa1所指的数大,就不pa1向后移动*/
        if(pb1->num<=pa1->num)
            {
                if(ah==pa1)
                    ah=pb1;
                else
                    pa2->next=pb1;
                pb1=pb1->next;
                pb2->next=pa1;
                pa2=pb2;
                pb2=pb1;
                }            /*把pb1接到pa中*/
        }while((pa1->next!=NULL)||((
            
            
            pa1==NULL)&&(pb1->next)!=NULL));
    if((pb1->num>pa1->num)&&(pa1->next==NULL))
        pa1->next=pb1;
    return ah;
    }
调试时输出
Loaded symbols for 'D:\Debug\hebing.exe'
Loaded 'C:\windows\system32\ntdll.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\apphelp.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\version.dll', no matching symbolic information found.
The thread 0x7D0 has exited with code 0 (0x0).
怎么办啊?源文件好像没错误?
搜索更多相关主题的帖子: 链表 顺序 
2010-05-13 13:20
wxh525123
Rank: 2
等 级:论坛游民
帖 子:38
专家分:37
注 册:2010-4-18
收藏
得分:0 
microsoft visual c++6.0system symbols setup安装路径谁知道啊?我的是windowsXP32位的
2010-05-13 14:38
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:10 
你自己装的不知道?
在工具 tool -> 添加 具体不知道了
百度有的

2010试用版出了 用2010吧 或者论坛置顶的GCC
2010-05-13 14:51
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:10 
顶版主

南国利剑
2010-05-13 23:56
快速回复:写两个有顺序的链表并合并
数据加载中...
 
   



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

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