注册 登录
编程论坛 数据结构与算法

大家快来帮我看看通过顺序结构实现栈哪里错了,为什么输出是这样啊?

dengdaisky 发布于 2013-05-14 23:55, 630 次点击
为什么输出全是000000000000000000000000啊
#include "stdafx.h"
#include <iostream>
using namespace std;
#define MaxSize 50
typedef struct
{
    int data[MaxSize];
    int top;
}Sqstack;
void init(Sqstack *&s)
{
    s=new Sqstack();
    s->top=-1;
}
bool push(Sqstack *&s,int e)
{
    if (s->top=MaxSize-1)
      return false;
    else
        s->top++;
    s->data[s->top]=e;
    return true;
}
void display(Sqstack *s)
{
    for (int i=s->top;i>=0;i--)
        cout<<s->data[i];
}
int _tmain(int argc, _TCHAR* argv[])
{
    Sqstack *s;
    init(s);
    push(s,5);
    push(s,4);
    display(s);
    return 0;
}

2 回复
#2
yuccn2013-05-15 10:59
  if (s->top=MaxSize-1)

这个~~
#3
dengdaisky2013-05-15 11:18
回复 2楼 yuccn
太马虎了,谢谢了啊
1