|
|
|
|
|
|
|
void InsertTop( /* in */ CardType newCard );
// Precondition:
// newCard is assigned
// Postcondition:
// newCard is inserted at top of pile
void RemoveTop( /* out */ CardType& topCard );
// Precondition:
// Length of card pile > 0
// Postcondition:
// topCard == value of first component in pile at entry
// && topCard is no longer in pile
CardPile();
// Postcondition:
// Empty pile is created
CardPile( const CardPile& otherPile );
// Postcondition:
// Pile is created as a duplicate of otherPile
~CardPile();
// Postcondition:
// Pile is destroyed
private:
NodeType* head;
int listLength;
};
#endif |
|
|
|
|
|
|
|
|
Implementation of the Class For the data representation of a card pile, we use a linked list. Furthermore, we implement the linked list using dynamic data and pointers. Each node is of type NodeType, whose complete declaration (hidden in the implementation file) is as follows: |
|
|
|
|
|
|
|
|
typedef NodeType* NodePtr;
struct NodeType
{
CardType card;
NodePtr link;
}; |
|
|
|
|
|