ITPub博客

首页 > > > 初学C++。求问为什么输出来的结果是这样的啊?

初学C++。求问为什么输出来的结果是这样的啊?

作者:ofan 时间:2019-09-24 14:58:54 0 删除 编辑
#include <iostream>
using namespace std;

#define StackSize 100
typedef char DataType;
typedef struct{
    DataType data[StackSize];
    int top;
}SeqStack;

void InitStack(SeqStack *S)
{//栈初始化 
    S->top = -1;
}

int StackEmpty(SeqStack *S)
{//判断栈是否为空 
    return S->top == -1;
}

int StackFull(SeqStack *S)
{//判断栈满 
    return S->top == StackSize - 1;
}

void Push(SeqStack *S, DataType x)
{//入栈 
    if (StackFull(S))
        perror("Stack overflow");
    S->data[S->top] = x;
    ++ S->top;
}

DataType Pop(SeqStack *S)
{//出栈 
    if (StackEmpty(S))
        perror("Stack underflow");
    return S->data[S->top];
    S->top --; 
}

DataType StackTop(SeqStack *S)
{//取栈顶元素 
    if (StackEmpty(S))
        perror("Stack is empty");
    return S->data[S->top];
}


int main()
{
    SeqStack *S;
    InitStack(S);
    Push(S, 'a');
    Push(S, 'b');
    cout << StackTop(S);
    
    return 0;
}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4571/viewspace-3125387/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-01

  • 博文量
    159
  • 访问量
    1163