The output is: 100 100
It should be: 9 100
I have called the push twice.When I call print, the output is wrong.
int main(){
int i=9;
Stackc s;
s.push(i);
i=100;
s.push(i);
s.print();
return 0;
}
this is the .h file
class Stackc{
int arr[100];
int iTop;
public:
int top();
void push(int i);
void pop();
void print();
Stackc();
};
this is the constructor
Stackc::Stackc(){
iTop=-1;
for(int i=0;i<100;i++)
arr[i]=0;
}
this function pushes an element into the stack
void Stackc::push(int i){
iTop++;
arr[iTop]=i;
}
this is for printing the stack
void Stackc::print(){
for(int i=0;i<=iTop;i++)
cout<<arr[iTop]<<" ";
cout<<endl;
}