Untitled
unknown
c_cpp
3 years ago
707 B
11
Indexable
#include <bits/stdc++.h>
// Stack class.
class Stack {
int *stack;
int capacity;
int size = 0;
public:
Stack(int capacity) {
stack = new int[capacity];
this -> capacity = capacity;
}
void push(int num) {
if (size < capacity) {
stack[size++] = num;
}
}
int pop() {
if (size > 0)
return stack[--size];
else return -1;
}
int top() {
if (size > 0)
return stack[size-1];
else return -1;
}
int isEmpty() {
return size == 0;
}
int isFull() {
return size == capacity;
}
};Editor is loading...