I keep getting errors in my code and I can't seem to fix it. Any Idea what it could be?
Code:
#include<iostream>
using namespace std;
class stack{
private:
int stackArray[3];
int top;
int size;
public:
void push(int x);
int pop();
int showSize();
void showElements();
stack();
~stack();
};
stack::stack(){
top = -1;
size = 0;
}
stack::~stack(){
}
void stack::push(int x){
if(size < 3}{
top++;
stackArray[size] = x;
size++;
}
}
int stack::pop(){
int x = stackArray[top];
top--;
size--;
return x;
}
int stack::showSize(){
return size;
}
void stack::showElements(){
for(int i = top; i > -1; i--){
cout<<stackArray[i]<<endl;
}
}
int main(){
int val;
stack s;
s.push(5);
s.push(4);
s.push(3);
cout<<"Size: "<<s.showSize()<<endl;
cout<<"Elements Pushed: ";
s.showElements();
val = s.pop();
s.pop();
s.pop();
cout<<"Last element Popped"<<val<<endl;
s.showElements();
return 0;
}