//--------------------------------------------------------------------
//
//  Laboratory 5                                          show5.cpp
//
//  Array and linked list implementations of the showStructure
//  operation for the Stack ADT
//
//--------------------------------------------------------------------

template < class DT >
void Stack<DT>:: showStructure () const

// Array implementation. Outputs the data items 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 << dataItem[j] << "\t";
       cout << endl;
    }
}

//--------------------------------------------------------------------

template < class DT >
void Stack<DT>:: showStructure () const

// Linked list implementation. Outputs the data items in a stack.
// If the stack is empty, outputs "Empty stack". This operation is
// intended for testing and debugging purposes only.

{
    StackNode<DT> *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->dataItem << " ";
       cout << "bottom" << endl;
    }
}

//--------------------------------------------------------------------

template < class DT >
void Stack<DT>:: showStructure () const

// "Downward" array implementation. Outputs the data items 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 << dataItem[j] << "\t";
       cout << endl;
    }
}

