标题:C语言求助 代码·
只看楼主
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册: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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-475138-1-1.html




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

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