Member Functions for Stack ADT - Array Implementation
// ********************************************************* // Implementation file StackA.cpp for the ADT stack. // Array-based implementation. // ********************************************************* #include "Stackarr.h" // header file Stack::Stack(): Top(-1) { } // end default constructor int Stack::isEmpty() { return (Top < 0); } // end isEmpty int Stack::push(stackItemType NewItem) { int Success = (Top < MAX_STACK - 1); if (Success) // if stack has room for another item { ++Top; Items[Top] = NewItem; } // end if return Success; } // end Push int Stack::pop() { int Success = !isEmpty(); if (Success) // if stack is not empty, --Top; // pop top return Success; } // end Pop int Stack::pop(stackItemType& StackTop) { int Success = !isEmpty(); if (Success) // if stack is not empty, { StackTop = Items[Top]; // retrieve top --Top; // pop top } // end if return Success; } // end Pop int Stack::top(stackItemType& StackTop) { int Success = !isEmpty(); if (Success) // if stack is not empty, StackTop = Items[Top]; // retrieve top return Success; } // end top // End of implementation file.
Email Me | Office Hours | My Home Page | Department Home | MCC Home Page