Skip to content

Instantly share code, notes, and snippets.

@npocmaka
Last active December 15, 2016 14:39
Show Gist options
  • Save npocmaka/234af582c10cbbc47cc6e04c14eeed43 to your computer and use it in GitHub Desktop.
Save npocmaka/234af582c10cbbc47cc6e04c14eeed43 to your computer and use it in GitHub Desktop.
// ConsoleApplication10.cpp : main project file.
#include "stdafx.h"
#include <iostream>
using namespace std;
const int MAX_SIZE = 100;
class ArrayStack
{
private:
int data[MAX_SIZE];
int top;
public:
ArrayStack()
{
top = -1;
}
void Push(int element)
{
if (top >= MAX_SIZE -1)
{
cout << "MAX SIZE REACHED\n";
return;
}
data[++top] = element;
}
int Pop()
{
if (top == -1)
{
cout << "STACK IS EMPTY\n";
return -1;
}
return data[top--];
}
int Top()
{
if (top == -1)
{
cout << "STACK IS EMPTY\n";
return -1;
}
return data[top];
}
int Size()
{
return top + 1;
}
bool isEmpty()
{
return (top == -1) ? true : false;
}
};
int main()
{
ArrayStack s;
if (s.isEmpty())
{
cout << "Stack is empty\n" << endl;
}
// Push elements
s.Push(100);
s.Push(200);
s.Push(300);
cout << s.Pop() << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment