| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1077 人关注过本帖
标题:为什么有段语句编译器不能通过?
取消只看楼主 加入收藏
hcanhong
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:58
专家分:0
注 册:2008-9-6
收藏
得分:0 
各位编程爱好者,我本人无意中发现解决方法;下面的修改后的程序:
/*      2.26   */

#include <stdio.h>
#include <stdlib.h>

#define LIST_INIT_SIZE 100
#define NULL 0

typedef struct LNode {
    int data;
    struct LNode *next;
}*LinkList;

LinkList creat(LinkList head)
{
    LinkList l, q, p;
    int ch;

    l = (LinkList)malloc(sizeof(LinkList));         
    l->data = 0;                             
    l->next = NULL;                     

    q = l;   
    p = l;

    printf("Input the Incremental s:\n");
    scanf("%d",&ch);    //printf("%d\n",ch);

    while (ch != 0)                              
    {
        p = (LinkList)malloc(sizeof(LinkList));            
        p->data = ch;
        p->next = NULL;                    
        q->next = p;                    
        q = p;                       
        scanf("%d",&ch);
        //printf("%d\n",ch);
    
    }
    q = l;
    return q;//It is OK!
}   

LinkList Mergelist(LinkList A,LinkList B)
{
    LinkList pa, pb, pc;

    LinkList l, s;


    l = (LinkList)malloc(sizeof(LinkList));         
         l->data = 0;                             
         l->next = NULL;   
    pa = A->next;
    pb = B->next;

    pc = l;

    while (pa && pb)
    {
        if (pa->data != pb->data)
        {
            pa = pa->next;
            pb = pb->next;
        }
        else
        {
            s = (LinkList)malloc(sizeof(LinkList));
            s->data = pa->data;
            pc->next = s;
            pc = s;
            pa = pa->next;
            pb = pb->next;
        }
    }

    pc = l;
    return pc;
}//    Mergelist



void Print(LinkList p)
{

    if (p != NULL)
    {
        do {
            printf(" %d",p->data);
            p = p->next;
        }
        while (p != NULL);
    }
    else
        printf("Wrong!\n");

    printf("\n\n");

    free(p);
}

int main()
{
    LinkList a, b, c;
    LinkList l;

    l = (LinkList)malloc(sizeof(LinkList));         
         l->data = 0;                          
         l->next = NULL;
    a = l;
    b = l;
    c = l;
    a = creat(a);
    b = creat(b);
         c = Mergelist(a, b);
    printf("Output the Descending series:\n");
    c = c->next;
    Print(c);
    return 0;
}
2008-10-02 12:40
hcanhong
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:58
专家分:0
注 册:2008-9-6
收藏
得分:0 
只是增加一个变量与一些内容:
 s = (LinkList)malloc(sizeof(LinkList));
            s->data = pa->data;
            pc->next = s;
            pc = s;
2008-10-02 12:41
hcanhong
Rank: 1
来 自:肇庆学院网络工程系
等 级:新手上路
帖 子:58
专家分:0
注 册:2008-9-6
收藏
得分:0 
谢谢各位的帮助~~
2008-10-02 12:42
快速回复:为什么有段语句编译器不能通过?
数据加载中...
 
   



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

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