#pragma once
#ifndef _SEQSTACK_
#define _SEQSTACK_
#include
using namespace std;
typedef int DataType;
struct SeqStack {
int MAXNUM;
int t;
DataType *s;
};
typedef SeqStack Node;
typedef SeqStack *PSeqStack;
PSeqStack creatEmptyStasck(int m) {
PSeqStack stack = new Node;
if (stack != NULL) {
stack->s = new DataType[m];
if (stack->s != NULL) {
stack->MAXNUM = m;
stack->t = -1;
}
}
return stack;
}
int isEmptyStack(PSeqStack stack) {
if (stack->t = -1)return 1;
else return 0;
}
void push_seq(PSeqStack stack, DataType x) {
if (stack->t >= stack->MAXNUM - 1) cout << "OverFlow" << endl;
else {
stack->t += 1;
stack->s[stack->t] = x;
}
}
void pop_seq(PSeqStack stack) {
if (stack->t == -1)cout << "Underflow!" << endl;
else {
stack->t -= 1;
}
}
DataType top_seq(PSeqStack stack) {
if (stack->t == -1) {
cout << "Underflow!" << endl;
}
else return (stack->s[stack->t]);
}
#endif
Original: https://www.cnblogs.com/iforeverhz/p/16255983.html
Author: iforeverhz
Title: 顺序栈
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/583238/
转载文章受原作者版权保护。转载请注明原作者出处!