鱼C论坛

 找回密码
 立即注册
查看: 2788|回复: 2

链表里的一个小问题

[复制链接]
头像被屏蔽
发表于 2012-5-20 17:42:42 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-5-21 11:02:04 | 显示全部楼层
兄弟。。。错误太多了,给你贴个修改过的代码,你自己看吧!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct test

{
        int data;
        struct test *next;
}wm;

wm *head = NULL;

int main()

{
                void Print_wm(wm *h);
                wm * Increate_wm(wm *h);
                wm * head = NULL;
   

        head = Increate_wm(head);
                Print_wm(head);

        system("pause");
                return 0;

}

void Print_wm(wm *h)
{

        wm *p = h;
                while(p != NULL)
                {

                printf("->%d\n",p->data);

                p = p->next;

        }

        printf("->End\n");
}

//添加数据

wm * Increate_wm(wm *h)

{

        wm *next = h;

        int x ;

                while(1)
                {
                        printf("输入数据:\n");
                        scanf("%d",&x);
                        if(x == 0)
                        {
                                break;
                        }
                        if(h == NULL)
                        {
                                h = (wm *)malloc(sizeof(wm));
                                next = h;
                                h->data = x;
                                h->next = NULL;
                        }
                        else
                        {
                                next->next = (wm *)malloc(sizeof(wm));
                                next = next->next;
                                next->data = x;
                                next->next = NULL;
                        }
                }
                return h;
}
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-5-21 11:04:03 | 显示全部楼层
你都错误是逻辑上的,不是语法上的。所以你能编译通过。本来想给你一一指出错误的。但是实在是太多了。所以就在你的基础上改了改。我也是个初学者,改的不好,对付看吧。呵呵
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-13 10:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表