标题:遍历输出问题,请大神帮帮忙。谢谢!
取消只看楼主
makoki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2018-8-23
结帖率:66.67%
已结贴  问题点数:10 回复次数:1 
遍历输出问题,请大神帮帮忙。谢谢!
# include <stdio.h>
# include <malloc.h>
# include <stdlib.h>

typedef struct Node
{
    int data;
    struct Node * pNext;
}NODE, * PNODE;

typedef struct Stack
{
    PNODE pTop;
    PNODE pBottom;
}STACK, * PSTACK;

void init(PSTACK);
void push(PSTACK, int );
void traverse(PSTACK);

int main()
{
    STACK S;
    int Val;

    init (&S);
   
    push(&S, 1);
    push(&S, 2);
    push(&S, 3);
    push(&S, 4);
    push(&S, 5);
    push(&S, 6);
   
    traverse(&S);

    return 0;
}

void init(PSTACK pS)
{
    pS->pTop = (PNODE)malloc(sizeof(NODE));
    if(NULL == pS->pTop)
    {
        printf("动态内存分配失败");
        exit(-1);
    }
    else
    {
        pS->pBottom = pS->pTop;
        pS->pTop->pNext = NULL;

    }
}

void push(PSTACK pS, int val)
{
    PNODE pNew = (PNODE)(sizeof(NODE));
    pNew->data = val;
    pNew->pNext = pS->pTop;
    pS->pTop = pNew;

    return;
}

void traverse(PSTACK pS)
{
    PNODE p = pS->pTop;

    while (p != pS->pBottom)
    {
        printf("%d ", p->data);
        p = p->pNext;
    }
    printf("\n");

    return;
}

没有报错,但是却不能输出,是什么问题呢?
搜索更多相关主题的帖子: void push int 输出 Node 
2020-04-16 20:44
makoki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2018-8-23
得分:0 
回复 2楼 wmf2014
额  谢谢!汗
2020-04-16 22:00



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




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

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