Files
data-structures-and-algorithms/homework3/Stack.cpp
T
2024-10-23 20:59:19 +08:00

42 lines
608 B
C++

#include "Stack.h"
#include<iostream>
using namespace std;
bool isEmpty(stack &s) {
if (s.top == -1) {
return true;
}
return false;
}
bool isFull(stack &s) {
if (s.top == MAX_SIZE) {
return true;
}
return false;
}
void initStack(stack &s) {
s.top = -1;
}
void push(stack &s, int e) {
if (isFull(s)) {
cout << "此栈已满" << endl;
return;
}
s.top++;
s.data[s.top] = e;
}
int pop(stack &s) {
if (isEmpty(s)) {
cout << "此栈为空" << endl;
return NULL;
}
int e = s.data[s.top];
return e;
}