Member Functions for Stack ADT - List-based Implementation
// ********************************************************* // Implementation file StackLst.cpp for the ADT stack. // ADT list implementation. // ********************************************************* #include "StackLst.h" // header file Stack::Stack() { } // end default constructor Stack::Stack(Stack& S): L(S.L) { } // end copy constructor Stack::~Stack() { } // end destructor int Stack::isEmpty() { return (L.length() == 0); } // end StackIsEmpty int Stack::push(stackItemType NewItem) { int Success = L.insert(1, NewItem); return Success; } // end Push int Stack::pop() { int Success = L.del(1); return Success; // Assertion: If list was empty at entry, Success is false. } // end Pop int Stack::pop(stackItemType& StackTop) { int Success = L.retrieve(1, StackTop); Success = L.del(1); return Success; // Assertion: If list was empty at entry, Success is false. } // end Pop int Stack::top(stackItemType& StackTop) { int Success = L.retrieve(1, StackTop); return Success; // Assertion: If list was empty at entry, Success is false. } // end GetStackTop // End of implementation file.
Email Me | Office Hours | My Home Page | Department Home | MCC Home Page