| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 419 人关注过本帖
标题:链表的最简单的问题
只看楼主 加入收藏
wly2014
Rank: 2
等 级:论坛游民
帖 子:29
专家分:19
注 册:2014-2-25
结帖率:88.89%
收藏
已结贴  问题点数:20 回复次数:2 
链表的最简单的问题
初学c语言链表,就不幸的卡在了这里
注释处为错误;
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h>            // Cannot open include file: 'alloc.h': No such file or directory
struct node{
    int data;
    struct node *next;
}

int main()
{
    struct node *head,*p1,*p2;
    head =(struct node *)malloc(sizeof(struct node));
    p1 =(struct node *)malloc(sizeof(struct node));
    p2 =(struct node *)malloc(sizeof(struct node));
    head->data=1000;head->next=p1;
    p1->data=1001;p1->next=p2;
    p2->data=1002;p2->next=NULL;
    while (head!=NULL){
        printf("%d\n",head->data);
        p1=head;
        head=head->next;
        free(p1);
    }
    return 0;
}
搜索更多相关主题的帖子: include c语言 file 
2014-05-09 19:43
kwxx
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:309
专家分:913
注 册:2009-5-11
收藏
得分:20 
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>            // 头文件名字错了。
struct node{
    int data;
    struct node *next;
} ;    //------少了分号

int main()
{
    struct node *head,*p1,*p2;

    head =(struct node *)malloc(sizeof(struct node));
    p1 =(struct node *)malloc(sizeof(struct node));
    p2 =(struct node *)malloc(sizeof(struct node));

    head->data=1000;    head->next=p1;
    p1->data=1001;    p1->next=p2;
    p2->data=1002;    p2->next=NULL;
    while (head!=NULL){
        printf("%d\n",head->data);
        p1=head;
        head=head->next;
        free(p1);
    }
    return 0;
}
2014-05-09 20:04
wly2014
Rank: 2
等 级:论坛游民
帖 子:29
专家分:19
注 册:2014-2-25
收藏
得分:0 
太感谢了
2014-05-09 20:44
快速回复:链表的最简单的问题
数据加载中...
 
   



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

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