| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 815 人关注过本帖
标题:链表为什么不输出
取消只看楼主 加入收藏
蓝桥
Rank: 2
等 级:论坛游民
帖 子:18
专家分:22
注 册:2014-2-26
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
链表为什么不输出
Description建立长度为n的单链表A和长度为m的单链表B,n>0,m>0。编程实现将B表链接在A表的尾端,形成一个单链表A。数据类型指定为字符型。

Input第一行为A表的长度n;


第二行为A表中的数据元素


第三行为B表的长度m;


第四行为B表中的数据元素。

Output输出为链接好后的A表中的所有数据元素。


Sample Input

4
A B C D
6
1 2 3 4 5 6


Sample Output

 A B C D 1 2 3 4 5 6
#include<stdio.h>
#include<stdlib.h>

struct ch
{
    char c;
    struct ch *next;
};

struct ch *creat_list();
struct ch *insert_list(struct ch *,struct ch *);
void print_list(struct ch *);

main()
{
    struct ch *p,*p1,*p2;

    p1=creat_list();
    p2=creat_list();

    p=insert_list(p1,p2);
    print_list(p);

    return 0;
}

struct ch *creat_list()
{
    int i=0,n;
    struct ch *p,*p1,*head=NULL;

    scanf("%d",&n);
    getchar();

    while(i<n)
    {
        p=(struct ch *)malloc(sizeof(struct ch));
        p->c=getchar();
        getchar();

        if(i==0)
            head=p;
        else
            p1->next=p;
        p1=p;
        i++;
    }
    p->next=NULL;
    return head;
}  

struct ch *insert_list(struct ch *p1,struct ch *p2)
{
    struct ch *head;
    head=p1;

    while(p1->next!=NULL)
        p1=p1->next;
    p1->next=p2;
    return head;
}

void print_list(struct ch *p)
{
    int i=0;
    while(p!=NULL)
    {
        if(i==0)
        {
            printf("%c",p->c);
            i=1;
        }
        else
            printf(" %c",p->c);
        p=p->next;
    }
}
这是我的代码,在VC上运行结果都对,为什么提交时根本就不输出,真不懂啦,我哪错啦??急求,谢谢
搜索更多相关主题的帖子: include 元素 
2014-03-21 20:24
蓝桥
Rank: 2
等 级:论坛游民
帖 子:18
专家分:22
注 册:2014-2-26
收藏
得分:0 
没有空格分隔?题目中的链表应该不包括空格,关键是根本就不输出数据,我的链表应该没问题啊,我真找不到哪不对,好恼火啊
2014-03-21 20:49
蓝桥
Rank: 2
等 级:论坛游民
帖 子:18
专家分:22
注 册:2014-2-26
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>

 struct ch
 {
     char c;
     struct ch *next;
 };

 struct ch *creat_list();//建立链表
 struct ch *insert_list(struct ch *,struct ch *);//插入链表操作
 void print_list(struct ch *);//打印链表

 main()
 {
     struct ch *p,*p1,*p2;

     p1=creat_list();//返回第一个链表的头指针
     p2=creat_list();//返回第二个链表的头指针

     p=insert_list(p1,p2);//返回插入链表的头指针
     print_list(p);

     return 0;
 }

 struct ch *creat_list()
 {
     int i=0,n;
     struct ch *p,*p1,*head=NULL;

     scanf("%d",&n);//链表长度
     getchar();//接收换行符

     while(i<n)
     {
         p=(struct ch *)malloc(sizeof(struct ch));
         p->c=getchar();
         getchar();//接收空格

         if(i==0)
             head=p;//使head指向第一个节点
         else
             p1->next=p;
         p1=p;
         i++;
     }
     p->next=NULL;
     return head;
 }  

 struct ch *insert_list(struct ch *p1,struct ch *p2)
 {
     struct ch *head;
     head=p1;

     while(p1->next!=NULL)
         p1=p1->next;
     p1->next=p2;//使第一个链表的最后一个节点指向第二个链表的第一个节点
     return head;
 }

 void print_list(struct ch *p)
 {
     int i=0;
     while(p!=NULL)
     {
         if(i==0)
         {
             printf("%c",p->c);
             i=1;
         }
         else
             printf(" %c",p->c);
         p=p->next;
     }
 }
2014-03-21 21:18
蓝桥
Rank: 2
等 级:论坛游民
帖 子:18
专家分:22
注 册:2014-2-26
收藏
得分:0 
用free()释放内存后还是提交时不输出
2014-03-22 10:43
蓝桥
Rank: 2
等 级:论坛游民
帖 子:18
专家分:22
注 册:2014-2-26
收藏
得分:0 

Compile OK!
We only display the pre 3000 bytes.
Testcase: 0 Wrong Answer
Datain:
4
A B C D
6
1 2 3 4 5 6
The white space means how many lines we have here.
Your Output:

Our Output:
A B C D 1 2 3 4 5 6

提交后系统出现这样的界面,不显示我的输出,是个啥错呢
2014-03-22 11:11
快速回复:链表为什么不输出
数据加载中...
 
   



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

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