Ai
1 Star 4 Fork 5

Shapper/C Data Structure

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sh_stack.cpp 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
Shapper 提交于 2022-10-31 17:55 +08:00 . 添加栈相关内容
//
// 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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/cloudcan/c-data-structure.git
git@gitee.com:cloudcan/c-data-structure.git
cloudcan
c-data-structure
C Data Structure
master

搜索帮助