| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 910 人关注过本帖
标题:新人求指教单链表~~~代码如下
只看楼主 加入收藏
也许这样
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-4-1
收藏
 问题点数:0 回复次数:7 
新人求指教单链表~~~代码如下
#include<stdio.h>
#include<stdlib.h>

typedef struct _student
{
    int No;
    char name[10];
    int age;
    char sex;
    int order;
}student;

typedef struct _Node
{
    student data;
    struct _Node *next;
}List;

List *Create_list()
{
    int data;
    student data1, data3, data5;
    student data2, data4;
    List *head = NULL, *pcur = NULL, *plist = NULL;
    head = (List *)malloc(sizeof(List));
    //head->data = 0;
    head->next = NULL;

    printf("\nPlease enter the data of node(-1:quit) ");
    scanf("%d",&(data1.No));
    scanf("%s", &(data2.name));
    scanf("%d", &(data3.age));
    scanf("%c", &(data4.sex));
    scanf("%d", &(data5.order));
    pcur = head;

    while (data != -1)
    {
        plist = (List *)malloc(sizeof(List));
        plist->data.No = data1.No;
        plist->data.age = data2.name;
        plist->data.name = data3.age;
        plist->data.sex = data4.sex;
        plist->data.order = data5.order;
        plist->next = NULL;

        pcur->next = plist;
        pcur = plist;

        printf("\nPlease enter the data of node(-1:quit) ");
        scanf("%d", &data);
    }
    return head;
}
int print(List *head)
{
    List *p = NULL;

    if (head == NULL)
    {
        return -1;
    }
    p = head->next;
    printf("begin");
    while (p)
    {
        printf("%d %s %d %c %d", p->data.No, p->data.name, p->data.age, p->data.sex, p->data.order);
        p = p->next;
    }
}

int main()
{
    List *head = NULL;
    head = Create_list();
    print(head);
    system("pause");
    return;
}

总是运行不了  求指教
搜索更多相关主题的帖子: include 
2015-04-01 16:43
jklqwe111
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:35
帖 子:336
专家分:1135
注 册:2014-4-13
收藏
得分:0 
printf("\nPlease enter the data of node(-1:quit) ");
    scanf("%d",&(data1.No));
    scanf("%s", &(data2.name));
    scanf("%d", &(data3.age));
    scanf("%c", &(data4.sex));
    scanf("%d", &(data5.order));
    pcur = head;

    while (data != -1)
    {
        plist = (List *)malloc(sizeof(List));
        plist->data.No = data1.No;
        plist->data.age = data2.name;
        plist->data.name = data3.age;
        plist->data.sex = data4.sex;
        plist->data.order = data5.order;
        plist->next = NULL;

        pcur->next = plist;
        pcur = plist;

        printf("\nPlease enter the data of node(-1:quit) ");
        scanf("%d", &data);
    }

data1__data5用一个即可
scanf("%d",&(data1.No));
    scanf("%s", data1.name);
    scanf("%d", &(data1.age));
    scanf("%c", &(data1.sex));
    scanf("%d", &(data1.order));


      plist->data.No = data1.No;
        plist->data.age = data2.name;
        plist->data.name = data3.age;
        plist->data.sex = data4.sex;
        plist->data.order = data5.order;

plist->data = data1;//一句即可


你的数据输入只能进行一次。
2015-04-01 17:41
也许这样
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-4-1
收藏
得分:0 
回复 2楼 jklqwe111
提示左操作数必须为左值
2015-04-01 19:16
jklqwe111
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:35
帖 子:336
专家分:1135
注 册:2014-4-13
收藏
得分:0 
回复 3楼 也许这样
如果修改过代码就贴出来,有问题不好猜。
2015-04-01 19:35
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
测试排版效果 代码我没改

程序代码:
#include<stdio.h>
#include<stdlib.h>

typedef struct _student
{
    int No;
    char name[10];
    int age;
    char sex;
    int order;
} student;

typedef struct _Node
{
    student data;
    struct _Node *next;
} List;

List *Create_list()
{
    int data;
    student data1, data3, data5;
    student data2, data4;
    List *head = NULL, *pcur = NULL, *plist = NULL;
    head = (List *)malloc(sizeof(List));
    //head->data = 0;
    head->next = NULL;

    printf("\nPlease enter the data of node(-1:quit) ");
    scanf("%d", &(data1.No));
    scanf("%s", &(data2.name));
    scanf("%d", &(data3.age));
    scanf("%c", &(data4.sex));
    scanf("%d", &(data5.order));
    pcur = head;

    while (data != -1)
    {
        plist = (List *)malloc(sizeof(List));
        plist->data.No = data1.No;
        plist->data.age = data2.name;
        plist->data.name = data3.age;
        plist->data.sex = data4.sex;
        plist->data.order = data5.order;
        plist->next = NULL;

        pcur->next = plist;
        pcur = plist;

        printf("\nPlease enter the data of node(-1:quit) ");
        scanf("%d", &data);
    }

    return head;
}
int print(List *head)
{
    List *p = NULL;

    if (head == NULL)
    {
        return -1;
    }

    p = head->next;
    printf("begin");

    while (p)
    {
        printf("%d %s %d %c %d", p->data.No, p->data.name, p->data.age, p->data.sex, p->data.order);
        p = p->next;
    }
}

int main()
{
    List *head = NULL;
    head = Create_list();
    print(head);
    system("pause");
    return;
}

2015-04-01 19:49
longwu9t
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:732
专家分:2468
注 册:2014-10-9
收藏
得分:0 
回复 楼主 也许这样
main.c(31,17) :  warning: format specifies type 'char *' but the argument has
      type 'char (*)[10]' [-Wformat]
    scanf("%s", &(data2.name));
           ~~   ^~~~~~~~~~~~~
                                                          ^
main.c(41,25) :  warning: incompatible pointer to integer conversion assigning
      to 'int' from 'char [10]' [-Wint-conversion]
        plist->data.age = data2.name;
                        ^ ~~~~~~~~~~
main.c(42,26) :  error: array type 'char [10]' is not assignable
        plist->data.name = data3.age;
        ~~~~~~~~~~~~~~~~ ^
                                                          ^
main.c(78,5) :  error: non-void function 'main' should return a value
      [-Wreturn-type]
    return;
    ^

Only the Code Tells the Truth             K.I.S.S
2015-04-01 20:50
也许这样
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-4-1
收藏
得分:0 
回复 5楼 zklhp
恩恩  已解决
2015-04-02 17:16
也许这样
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-4-1
收藏
得分:0 
回复 6楼 longwu9t
  谢谢
2015-04-02 17:16
快速回复:新人求指教单链表~~~代码如下
数据加载中...
 
   



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

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