Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class MyStackArray
- {
- private:
- int *DATA;
- int count;
- int capacity;
- public:
- MyStackArray() {
- DATA = new int[3];
- count = 0;
- capacity = 3;
- }
- int *getData() {
- return DATA;
- }
- int getCount() {
- return count;
- }
- int getCapacity() {
- return capacity;
- }
- void setData(int *data) {
- DATA = data;
- }
- void setCount(int c) {
- count = c;
- }
- void setCapacity(int cap) {
- capacity = capacity;
- }
- bool isFull()
- {
- return count == capacity;
- }
- void push(int item)
- {
- if(!isFull())
- DATA[count++] = item;
- else
- cout << "Stack is FULL...\n";
- }
- bool isEmpty()
- {
- return count==0;
- }
- void pop()
- {
- if (!isEmpty())
- count--;
- else
- cout << "Stack is Empty!";
- }
- int peek()
- {
- return DATA[count-1];
- }
- void display()
- {
- cout << "\nS[";
- for (int i = 0; i < count; i++)
- cout << " " << DATA[i];
- cout << "]" << endl;
- }
- };
- int main(int argc, char** argv) {
- MyStackArray ms;
- ms.push(4);
- ms.push(7);
- ms.push(10);
- ms.push(20);
- ms.display();
- cout << "\nNaa sa babaw = " << ms.peek() << endl;
- ms.pop();
- ms.pop();
- ms.pop();
- ms.pop();
- ms.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement