< previous page page_1088 next page >

Page 1088
    listLength = otherPile.listLength;
    if (otherPile.head == NULL)
    {
        head = NULL;
        return;
    }

    // Copy first node

    fromPtr = otherPile.head;
    head = new NodeType;
    head->card = fromPtr->card;

    // Copy remaining nodes

    toPtr = head;
    fromPtr = fromPtr->lirik;
    while (fromPtr != NULL)
    {
            // Invariant (prior to test):
            //     The list from *head through *toPtr is a copy of
            //     the list from *(otherPile.head) through the node
            //     preceding *fromPtr

        toPtr->link = new NodeType;
        toPtr = toPtr->link;
        toPtr->card = fromPtr->card;
        fromPtr = fromPtr->link;
    }
    toPtr->link = NULL;
}

//******************************************************************

CardPile::~CardPile()

// Destructor

// Postcondition:
//     All linked list nodes have been deallocated from free store

{
    CardType temp;    // Temporary variable

    while (listLength > 0)

            // Invariant (prior to test):

 
< previous page page_1088 next page >