Server IP : 172.16.15.8 / Your IP : 18.118.144.98 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/grpatillo/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
/* File Name: stackarray.cpp Author: R.P. Patillo Instructor: Dr. Ames Due Date: Oct. 23, 2008 Complilation: g++ stackclient.cpp -o stackclient.out Execution: ./stackclient.out */ // Implementation file for Stack ADT. // Class definition is in "stackarray.h" // Class is templated. // //--------------------------------------------------------------------------- // Stack Constructor - initializes an empty stack //--------------------------------------------------------------------------- template<class ItemType> StackType<ItemType>::StackType() { top = -1; } //--------------------------------------------------------------------------- // IsEmpty - tests for empty stack //--------------------------------------------------------------------------- // Returns true if empty, false otherwise //--------------------------------------------------------------------------- template<class ItemType> bool StackType<ItemType>::IsEmpty() const { return (top == -1); } //--------------------------------------------------------------------------- // IsFull - tests for empty stack //--------------------------------------------------------------------------- // Returns: true if full, false otherwise //--------------------------------------------------------------------------- template<class ItemType> bool StackType<ItemType>::IsFull() const { return (top == MAXSTACK - 1); } //--------------------------------------------------------------------------- // Push - adds item to top of stack //--------------------------------------------------------------------------- // Accepts: Item to be added //--------------------------------------------------------------------------- template<class ItemType> void StackType<ItemType>::Push(ItemType newItem) { if (!IsFull()) { top++; items[top] = newItem; } else cout << "Error - Pushing " << newItem << " onto full stack!"; } //--------------------------------------------------------------------------- // Pop - removes top item from stack //--------------------------------------------------------------------------- template<class ItemType> void StackType<ItemType>::Pop() { if (!IsEmpty()) top--; else cout << "Error - Popping an empty stack!"; } //--------------------------------------------------------------------------- // Top - shows copy of top stack item leaving stack structure intact //--------------------------------------------------------------------------- // Returns: copy of top item //--------------------------------------------------------------------------- template<class ItemType> ItemType StackType<ItemType>::Top() { if (!IsEmpty()) return items[top]; else cout << "Error - Viewing top of empty stack - returned item ??"; } //---------------------------------------------------------------------------- // CopyNth - returns a copy of the item located in the Nth position of a stack //---------------------------------------------------------------------------- // Returns: copy of Nth item //--------------------------------------------------------------------------- template<class ItemType> void StackType<ItemType>::CopyNth(int N, ItemType& copyitem) { copyitem = items[top-(N-1)]; //copyitem = items N from the top }