张麻子


私信TA

用户名:qwezjh

访问量:2467

签 名:

上任鹅城

等  级
排  名 835
经  验 3499
参赛次数 0
文章发表 25
年  龄 0
在职情况 学生
学  校 asd
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include "stdio.h"

#include "stdlib.h"

#define MaxSize 100

typedef int ElemType;

typedef struct 

{

ElemType data[MaxSize];

int top;

}SqStack;


void init(SqStack& S) 

{

S.top = -1;

}

bool push(SqStack& S, ElemType e) 

{

if (S.top == MaxSize - 1) 

{

return false;

}

S.top++; S.data[S.top] = e;

return true;

}

bool pop(SqStack& S, ElemType& x) 

{

if (S.top == -1) { return false; }

x = S.data[S.top];

S.top--;

return true;

}

void print(SqStack S) 

{

for (int i = 0; i <= S.top; i++) 

{

printf("%d ", S.data[i]);

}

}

int main()

{

int n;

while (scanf("%d", &n)!=EOF)

{

if (n == 0) { break; }

SqStack S;

init(S);

ElemType X;

char A[2];

for (int i = 0; i < n; i++) 

{

scanf("%s", A);// (A);

if (A [0]== 'P') 

{

int x;//getchar();

scanf("%d", &x); 

push(S, x);

}

if (A[0] == 'O') 

{

if (S.top == -1) { continue; }

int E;

pop(S,E);

}

if (A [0]== 'A') 

{

if (S.top == -1) { printf("E\n"); continue; }

printf("%d\n", S.data[S.top]);

}

}

printf("\n");

}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区