| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1417 人关注过本帖
标题:数据结构 构造一个空的链表.我写了个,大家看下,然后帮我写一个好的.我 ...
只看楼主 加入收藏
andytony1234
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:74
专家分:102
注 册:2009-11-9
结帖率:100%
收藏
 问题点数:0 回复次数:3 
数据结构 构造一个空的链表.我写了个,大家看下,然后帮我写一个好的.我好参考..谢谢了...
#include<stdio.h>
#include<stdlib.h>
#define SIZE 30
    struct node
    {
        char name[10];
        int  num;
        float score;
        struct node *next;
    }node,*p;
    InitList()
    {
        if((node.next=malloc(SIZE))==NULL)
            printf("malloc error");
        return(node);
    }
搜索更多相关主题的帖子: 链表 构造 数据结构 
2010-01-26 20:41
shiyongdong
Rank: 1
等 级:新手上路
帖 子:8
专家分:4
注 册:2010-2-20
收藏
得分:0 
如果我没有猜错的话,你想建立一个链表,包含的信息有4项比如:
学生的姓名
学生证号码
学生成绩
以及一个指向下个链表格子的指针,
我觉得在你的fonction of initialization 中我觉得你要初始化前3项信息
我的建议是:
void InitList()/*your fonction must contain a return value , here , we just realize an action of creation , so we put a void */

{
   for(int i=0; i<N;i++)
   {
     p=malloc(sizeof(node));/*allocation of memory for just a node*/
     p->name[10]=" ";/*put a global string for initization please*/
     p->num=0;/*idem*/
     p->score=0.0;/*idem*/
     p=p->next;/*link to the next node*/
    }
    p->next=NULL; /*last pointer of node point to NULL!*/
  }
希望我的代码对你有帮助
2010-02-21 07:02
asd451006071
Rank: 2
等 级:论坛游民
帖 子:23
专家分:20
注 册:2008-11-30
收藏
得分:0 
错了,结构体只定义内部数据的组合形式,要先定义变量才能用node.next其它的都可以,难为我用手机敲的难受
2010-02-21 17:23
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:0 
struct node
{
    char name[10];
    int  num;
    float score;
    struct node *next;
}node,*p;
void InitList()
{
    if((node.next=(struct node *)malloc(sizeof(struct node)))==NULL)
        printf("malloc error\n");
    else
        printf("malloc ok\n");
}
int main()
{
    InitList();
    free(node.next);
    return 0;
}

★★★★★为人民服务★★★★★
2010-02-22 07:16
快速回复:数据结构 构造一个空的链表.我写了个,大家看下,然后帮我写一个好的 ...
数据加载中...
 
   



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

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