I am trying to make a simple application based on stack and my code is giving an error when I am trying to run it. The code is here:
// Stacks.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace std;
class stackx{
private:
int top;
vector<double> stackVect;
int maxSize;
public:
stackx(int s): maxSize(s),top(-1){
stackVect.reserve(maxSize);
}
void push(double a){
stackVect[++top]=a;
}
double pop(){
return stackVect[top--];
}
double peek(){
return stackVect[top];
}
bool isEmpty(){
return (top==-1);
}
bool isFull(){
return (top == maxSize-1);
}
};
int main(){
stackx stackvect(6);
stackvect.push(20);
stackvect.push(22);
stackvect.push(13);
stackvect.push(69);
stackvect.push(123);
while(!stackvect.isEmpty()){
double value = stackvect.pop();
cout<<value<<" ";
}
cout<<endl;
return 0;
}
Where am I making the mistake ?