need some experts' suggestion, would appreciate your help , thank you.
- Code: Select all
#define MAX 100
int stack[MAX];
int top = 0; // first empty place
// add an element
int push (int x) {
if (top == MAX) return 0; // stack is full, operation failed
stack[top++] = x;
return 1; // operation succeeded
}
// take an element
int pop () {
int x;
if (top == 0) return -1; // stack is empty, operation failed (return -1, or any other negative number,
// or 0, if stack contains natural numbers)
x = stack[--top];
return x;
}
// read the top, without removing the element
int read() {
int x;
if (top == 0) return -1; // stack is empty, operation failed
x = stack[top];
return x;
}
// is stack empty
int empty() {
if (top == 0) return 1;
else return 0;
}
// is stack full
int full() {
if (top == MAX) return 1;
else return 0;
}