代码拉取完成,页面将自动刷新
//
// Created by Win10 on 2022/10/31.
//
#include<iostream>
#include "sh_stack.h"
using namespace std;
bool StackEmpty(ShStack S) {
if (S.top0 == -1 && S.top1 == MaxSize) {
return true;
}
return false;
}
bool StackFull(ShStack S) {
if (S.top0 + 1 == S.top1) return true;
return false;
}
bool Push0(ShStack& S, ElemType x) {
if (StackFull(S) ){
return false;
}
S.data[++S.top0] = x;
return true;
}
bool Push1(ShStack& S, ElemType x) {
if (StackFull(S) ){
return false;
}
S.data[--S.top1] = x;
return true;
}
bool Pop0(ShStack& S, ElemType& x) {
if (S.top0 == -1) return false;
x = S.data[S.top0--];
return true;
}
bool Pop1(ShStack& S, ElemType& x) {
if (S.top1 == MaxSize) return false;
x = S.data[S.top1++];
return true;
}
bool GetTop0(ShStack S, ElemType& x) {
if (S.top0 == -1) return false;
x = S.data[S.top0];
return true;
}
bool GetTop1(ShStack S, ElemType& x) {
if (S.top1 == MaxSize) return false;
x = S.data[S.top1];
return true;
}
int main() {
{
ShStack S;
InitStack(S);
for (int i = 1; i <= 5; i++) {
Push0(S, i);
}
for (int i = 1; i <= 5; i++) {
Push1(S, i);
}
ElemType x;
GetTop0(S, x);
cout << x << endl;
GetTop1(S, x);
cout << x << endl;
bool f = Push0(S, 6);
if (f) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
f = Push1(S, 6);
if (f) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
while (Pop0(S,x)) {
cout << x << endl;
}
while (Pop1(S, x)) {
cout << x << endl;
}
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。