6999分段错误-C ++

这是我的代码:

#include <iostream>
using namespace std;
#define MAX 5 

结构定义:

struct Stack{
    int data[MAX];
    int top;
};

检查堆栈是否已满:

bool isFull(int tmpTop){
    return (tmpTop==(MAX-1));
}

检查堆栈是否为空:

bool isEmpty(int tmpTop){
    return (tmpTop==-1);
}

将数据添加到堆栈:

void push(Stack *ptrStack, int n){
    if(isFull(ptrStack->top)){
        cout<<"Stack is full! Push aborted!\n";        
    }else {
        ptrStack->top++;
        ptrStack->data[ptrStack->top]=n;
    }

}

获取堆栈的大小:

int getSize(int tmpTop){
    return tmpTop+1;
}

显示堆栈:

void displayStack(Stack tmpStack){
    if(isEmpty(tmpStack.top)){
        cout<<"Stack is empty! Displaystack is aborted!\n";
    }else {
        for(int i=0;i<=tmpStack.top;i++){
            cout<<tmpStack.data[i]<<" ";
        }
    }
}

返回堆栈中的值:

int pop(Stack *ptrStack){
    int data = -1 ; 
    if(isEmpty(ptrStack->top)){
        cout<<"Stack is empty! Pop is aborted!\n";
    }else {
        data=ptrStack->data[ptrStack->top];
        ptrStack->top--;
    }
    return data;
}

主要方法:

int main(){
    Stack aStack;
    push(&aStack,11);
    push(&aStack,22);
    push(&aStack,33);
    displayStack(aStack);
    return 0;
}

This is the output : enter image description here