i have write phase code to Mystack, but its error in declare dynamic array, can you help me, fix it? thanks
Code:
#include "iostream"
using namespace std;
class MyStack{
public:
MyStack();
~MyStack();
int Pop();
void Push(int item);
void IsFull();
void IsEmpty();
private:
//int this->size=5;
int *Arr=new Arr[5];
int index=-1;
};
MyStack::MyStack();
MyStack::~MyStack(){
delete(Arr);
}
int MyStack::Pop(){
index=index -1;
return Arr[index--];
}
void MyStack::Push(int item){
Arr[index]=item;
index++;
}
void MyStack::IsFull(){
if((size-1)==index)
cout<<" Stack is full";
}
void MyStack::IsEmpty(){
if(index==-1)
cout<<"Stack is Empty";
}
void main(){
MyStack s;
s.Push(6);
s.Push(3);
s.Push(2);
s.Push(5);
cout<<s.Pop();
}