| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2117 人关注过本帖
标题:C语言求助 代码·
只看楼主 加入收藏
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:4 
我刚学的啊  现学现卖  没准会有大的bug
程序代码:
#include <stdio.h>
#include <malloc.h>

#define N 9

typedef struct data
{
    int value;
    struct data* next;
}tdata,*pdata;


void prnlist(pdata head)
{
    pdata pfirst=head->next;
    while(pfirst!=NULL)
    {
        printf("%d  ",pfirst->value);
        pfirst=pfirst->next;
    }
    printf("\n");
}


int main(int argc, char* argv[])
{
    pdata  head1,pfirst1,psecond1;
    pfirst1=(pdata)malloc(sizeof(tdata));
    head1=pfirst1;
    head1->value=0;
    head1->next=NULL;
    psecond1=pfirst1;
    int i;
    printf("请录入第一组数据 :\n");
    for(i=0;i<N;i++)
    {
        pfirst1=(pdata)malloc(sizeof(tdata));
        scanf("%d",&pfirst1->value);
        pfirst1->next=NULL;
        psecond1->next=pfirst1;
        psecond1=pfirst1;
    }
    printf("请录入第二组数据:\n");
    pdata pfirst2=(pdata)malloc(sizeof(tdata));
    pdata head2=pfirst2;
    head2->value=0;
    head2->next=NULL;
    pdata psecond2=pfirst2;
    for(i=0;i<N;i++)
    {
        pfirst2=(pdata)malloc(sizeof(tdata));
        scanf("%d",&pfirst2->value);
        pfirst2->next=NULL;
        psecond2->next=pfirst2;
        psecond2=pfirst2;
    }
    printf("你所录入的两组数据如下:\n");
    prnlist(head1);
    prnlist(head2);
    printf("共有数据如下:\n");
    for(pfirst1=head1->next;pfirst1!=NULL;pfirst1=pfirst1->next)
    {
        for(pfirst2=head2->next;pfirst2!=NULL;pfirst2=pfirst2->next)
        {
            if(pfirst2->value==pfirst1->value) printf("%d  ",pfirst2->value);
        }
    }
    printf("\n");
    //free(head1);
    //free(head2);
    return 0;
}

/*
请录入第一组数据 :
1 2 3 4 5 6 7 8 9
请录入第二组数据:
2 3 4 5 6 7 8 9 10
你所录入的两组数据如下:
1  2  3  4  5  6  7  8  9
2  3  4  5  6  7  8  9  10
共有数据如下:
2  3  4  5  6  7  8  9
*/

 

[此贴子已经被作者于2017-3-23 22:17编辑过]


DO IT YOURSELF !
2017-03-23 21:25
Mintao
Rank: 2
等 级:论坛游民
帖 子:48
专家分:88
注 册:2017-3-3
收藏
得分:0 
大神可能有点忙啊!

学习,学习,学习
2017-03-24 14:03
快速回复:C语言求助 代码·
数据加载中...
 
   



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

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