解题思路:
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:517 |
大家好,我是验题君浏览:577 |
C二级辅导-同因查找 (C语言代码)浏览:568 |
复数求和 (C语言代码)浏览:929 |
输入输出格式练习 (C语言代码)浏览:753 |
青年歌手大奖赛_评委会打分 (C语言代码)浏览:2151 |
小O的数字 (C语言代码)浏览:1411 |
C语言训练-最大数问题 (C语言代码)浏览:591 |
C语言程序设计教程(第三版)课后习题7.2 (C++代码)浏览:437 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:634 |