Stack

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Stack as PDF for free.

More details

  • Words: 122
  • Pages: 2
// class template of the stack ADT // The member functions are defined outside of the class declaration const int STACK_CAPACITY=10; template class Stack { public: Stack(); void push(stackElement); void pop(); stackElement top(); bool isEmpty(); bool isFull(); private: stackElement stackArray[STACK_CAPACITY]; int stackTop; }; template Stack<stackElement>::Stack() { stackTop=-1; } template void Stack<stackElement>::push(stackElement x) { if(!isFull()) { stackTop++; stackArray[stackTop]=x; } else cout<<"Push oporation failed. The stack is full."<<endl; } template void Stack<stackElement>::pop() { if (!isEmpty()) { stackTop -- ; } else cout<<"Pop operation failed. The stack is empty."<<endl; } template stackElement Stack<stackElement>::top() { return stackArray[stackTop]; } template bool Stack<stackElement>::isEmpty()

{ }

return (stackTop==-1);

template bool Stack<stackElement>::isFull() { return (stackTop==STACK_CAPACITY-1); }

Related Documents

Stack
May 2020 16
Stack
April 2020 21
Stack
June 2020 14
Stack
November 2019 19
Stack
November 2019 19
Stack
December 2019 22