标题:链式栈为什么遍历不出来?
取消只看楼主
cwl168
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2012-12-14
结帖率:8.33%
 问题点数:0 回复次数:0 
链式栈为什么遍历不出来?
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct Node
{
     int data;
     struct Node * next;
}Node;
typedef struct Stack
{
    Node * top;
    Node * base;
}Stack;
void Inti(Stack *s)
{
   Node *N=(Node *)malloc(sizeof(Node));
   s->base=s->top=N;
   s->top->next=NULL;//这里必须是s->top->next=NULL;
   printf("Inti Success!\n");

}
void Push(Stack *s,int e)
{
      Node *p=(Node*)malloc(sizeof(Node));
      p->data=e;p->next=s->top->next;
      s->top=p;
      printf("Push Success!\n");
}
void print(Stack *s)
{
     Node * p = s->top;
    if(s->top==s->base)
    {
         printf("The stack is empty!\n");
    }
    while (p !=s->base)
    {
        printf("%d\n", p->data);
        p =p->next;
    }
    printf("\n");
    return;
}

int main()
{   
     Stack *s;
     s=(Stack *)malloc(sizeof(Stack));
     Inti(s);
     Push(s,1);
     Push(s,2);
     Push(s,3);
     Push(s,4);
     Push(s,5);
     print(s);
     return 0;
}
为什么遍历不出来?
搜索更多相关主题的帖子: top next include 
2012-12-21 15:52



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




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

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