数据结构基础问题:顺序栈出栈出错

顺序栈出栈出错,调试了好久,未果,求解惑!谢谢大家!

#include "stdafx.h"
#include <iostream>
using namespace std;

typedef int ElemType;
extern void Error(char * s);
enum Status {
    OK,
    ERROR,
    OVERFLOW1
};

#define Stack_Size 100

struct SqStack {
    ElemType* elem;     //栈的存储空间
    int top;            //栈顶指针
    int stacksize;
    SqStack();//构造函数

};

Status Pop_Sq(SqStack &S, ElemType &x);

SqStack::SqStack()//构造函数
{
    elem = NULL;
}

//1.初始化栈
Status InitStack_Sq(SqStack &S)
{
    S.elem = new ElemType[Stack_Size];
    S.top = 0;
    S.stacksize = Stack_Size;
    return OK;
}

//2.销毁栈
Status DestroyStack_Sq(SqStack &S)
{
    if (S.stacksize != 0)
        delete S.elem;
    S.top = NULL;
    S.stacksize = 0;
    return OK;
}

//3.求栈长
int StackLength_Sq(const SqStack &S)
{
    return S.stacksize;//自行修改
}

//4.获得栈顶元素到x,返回true,如果空栈,返回false
Status GetTop_Sq(const SqStack &S, ElemType &x)
{
    if (S.stacksize == 0)
        return ERROR;
    else
        x = S.elem[S.top];
    return OK;
}

//5.入栈: 把x压入栈
Status Push_Sq(SqStack &S, ElemType x)
{
    if (S.top == S.stacksize)
        return OVERFLOW1;
    S.elem[S.top] = x;
    S.top++;

    return OK;
}


//6.出栈:如果栈空,返回false;否则,"弹出"栈顶元素到x
Status Pop_Sq(SqStack &S, ElemType &x)
{
    if (S.stacksize == 0)
        return OVERFLOW1;
    S.top--;
    S.elem[S.top] = x;

    return OK;
}

void Error(char * s)
{
    cout << s << endl;
    system("pause");
    exit(1);//不退出程序
}
int main(int argc, char* argv[])
{
    int i;
    //顺序栈的测试
    SqStack Stack;
    InitStack_Sq(Stack);//初始化栈
    cout << "测试顺序栈" << endl;
    cout << "进栈元素依次为:" << endl;

    for ( i = 0 ; i < 100 ; i ++ )
    {
        Push_Sq( Stack , i ) ;//入栈顺序为0,1,2,3,...,99(自行添加出错处理)
        cout << i << "  ";
    }
        cout << endl << "依次弹出的栈顶元素为:" << endl;

    while ( Pop_Sq( Stack , i ) == OK )//出栈,输出出栈的元素
    {
        cout<< i <<" ";

    }
    cout<<endl;

    DestroyStack_Sq(Stack);//销毁栈
    cout << "退出main函数" << endl;
    system("pause");

    return 0;
}

http://blog.csdn.net/zqt520/article/details/8010485