Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- using namespace std;
- #define MAX_SIZE 10
- typedef struct Stack {
- int _data[MAX_SIZE];
- unsigned int _top = 0;
- bool isEmpty() {
- if (_top == 0) return true;
- else return false;
- }
- bool isFull() {
- if (_top == MAX_SIZE) return true;
- else return false;
- }
- void push(int newVal) {
- if (!isFull()) {
- _data[_top] = newVal;
- _top++;
- }else cout<<"Stack is Full"<<endl;
- }
- void pop() {
- if (!isEmpty()) {
- _top--;
- }
- else {
- cout << "Stack is Empty" << endl;
- }
- }
- int top() {
- if (!isEmpty()) {
- return _data[_top - 1];
- }
- else {
- cout << "Stack is Empty" << endl;
- }
- }
- int size() {
- return _top;
- }
- void reset() {
- _top = 0;
- }
- void print() {
- int temp = _top - 1;
- while (temp >= 0) {
- cout << _data[temp] << endl;
- temp--;
- }
- }
- };
- int main() {
- cout << "test" << endl;
- Stack s1;
- s1.reset();
- s1.print();
- s1.push(3);
- s1.push(5);
- cout << "Top:" << s1.top() << endl;
- s1.push(2);
- cout << "Top:" << s1.top() << endl;
- s1.print();
- s1.pop();
- s1.print();
- s1.push(1);
- cout << "Top:" << s1.top() << endl;
- s1.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement