An implementation of Stack data structure #include #include #include #include using namespace std; #if !defined __STACK_H #define __STACK_H namespace stk{ class Stack{ private: int *p; int top,length; string str()const; public: Stack(); Stack(const int); Stack(const Stack&); ~Stack(); void push(int); int pop(); int get_length()const; bool is_empty()const; Stack operator=(const Stack&); friend ostream& operator<<(ostream&,Stack&); class StackException{ private: string desc; public: StackException(string exp){ desc="Exception : "+exp; } string get_exp(){ return desc; } }; }; Stack::Stack(){ top=-1; length=0; p=0; } Stack::Stack(const int size){ top=-1; length=size; try{ p=new int[length]; }catch(bad_alloc ba){ cout<<"Memory can not be alllocated "; return; } } Stack::Stack(const Stack &o){ top=o.top; length=o.length; try{ p=new int[length]; }catch(bad_alloc ba){ cout<<"Memory allocation failed "; return; } for(int i=0;i