can any one please identify the mistake in my code???
my code is::
#include<iostream>
using namespace std;
class Stack{
int *arr;
int size;
int top;
public:
Stack(){arr = NULL; top = 0;}
Stack(int sz){
arr = new(nothrow) int[sz];
if(!arr) exit(1);
size = sz;
top = 0;
}
~Stack(){delete []arr;}
int pop();
void push(int i);
bool isEmpty();
bool isFull();
};
int Stack::pop()
{
top--;
return arr[top];
}
void Stack::push(int x)
{
arr[top] = x;
top++;
}
bool Stack::isFull()
{
return (top<size) ? false : true;
}
bool Stack::isEmpty()
{
return (top>0) ? false : true;
}
void pushElem(Stack &s, int i)
{
if(!s.isFull())
{
cout << "Pushing " << i << " into stack" << endl;
s.push(i);
}
else{
cout << "Error: Stack is full" << endl;
}
}
int popElem(Stack &s)
{
if(!s.isEmpty())
{
int ret = s.pop();
cout << "Popping " << ret << " from stack" << endl;
return ret;
}
else
{
cout << "Error: Stack is empty" << endl;
return -1;
}
}
int main()
{
cout << "Stack Example" << endl;
Stack s(10);
pushElem(s, 1);
pushElem(s, 2);
popElem(s);
popElem(s);
for ( int i = 0; i<11; i++)
pushElem(s, i*10);
for ( int i = 0; i<11; i++)
popElem(s);
}
when i compiled it the following error is exhibited:
$g++ -o try tryone.cpp
tryone.cpp: In constructor ‘Stack::Stack(int)’:
tryone.cpp:14: error: ‘exit’ was not declared in this scope