Stack and Queue Question
Nov 1, 2015 at 11:06pm UTC
Hello everyone,
Can anyone help with some advice as to how I can transform this code from Stack to Queue?
Can you guys give me any tips that I can use also in the future?
The code does not need a main part.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#include "stdafx.h"
#include <iostream>
using namespace std;
class Stack
{
private :
int stackArray[5];
int top;
public :
Stack()
{
top = -1;
}
bool empty()
{
if (top==-1)
return 1;
else
return 0;
}
int size()
{
if (top == 4)
return 1;
else
return 0;
}
void push(int n)
{
if (!size())
{
top++;
stackArray[top] = n;
}
else
{
cout<<"Stack has reached the maximum size" <<endl;
}
}
int pop()
{
int num;
if (!empty())
{
num = stackArray[top];
top--;
return num;
}
else
{
cout<<"Stack is empty" <<endl;
return 0;
}
}
};
Topic archived. No new replies allowed.