//-------------------------------------------------------------------- // // Laboratory 5 show5.cpp // // Array and linked list implementations of the showStructure // operation for the Stack ADT // //-------------------------------------------------------------------- template < class SE > void Stack:: showStructure () const // Array implementation. Outputs the elements in a stack. If the // stack is empty, outputs "Empty stack". This operation is intended // for testing and debugging purposes only. { int j; // Loop counter if ( top == -1 ) cout << "Empty stack" << endl; else { cout << "top = " << top << endl; for ( j = 0 ; j < maxSize ; j++ ) cout << j << "\t"; cout << endl; for ( j = 0 ; j <= top ; j++ ) cout << element[j] << "\t"; cout << endl; } } //-------------------------------------------------------------------- template < class SE > void Stack:: showStructure () const // Linked list implementation. Outputs the elements in a stack. If // the stack is empty, outputs "Empty stack". This operation is // intended for testing and debugging purposes only. { StackNode *p; // Iterates through the stack if ( top == 0 ) cout << "Empty stack" << endl; else { cout << "top "; for ( p = top ; p != 0 ; p = p->next ) cout << p->element << " "; cout << "bottom" << endl; } } //-------------------------------------------------------------------- template < class SE > void Stack:: showStructure () const // "Downward" array implementation. Outputs the elements in a stack. // If the stack is empty, outputs "Empty stack". This operation is // intended for testing and debugging purposes only. { int j; // Loop counter if ( top == maxSize ) cout << "Empty stack" << endl; else { cout << "top = " << top << endl; for ( j = 0 ; j < maxSize ; j++ ) cout << j << "\t"; cout << endl; for ( j = 0 ; j < maxSize ; j++ ) if ( j < top ) cout << " \t"; else cout << element[j] << "\t"; cout << endl; } }