|
|
|
|
|
|
|
//******************************************************************
void CardDeck::Merge( /* inout */ CardPile& shorterList,
/* inout */ CardPile& longerList )
// Merges shorterList and longerList into deck
// Precondition:
// Length of shorterList > 0 && Length of longerList > 0
// && Length of deck == 0
// Postcondition:
// Deck is the list of cards obtained by merging
// shorterList@entry and longerList@entry into one list
// && Length of shorterList == 0
// && Length of longerList == 0
{
CardType tempCard; // Temporary card
// Take one card from each list alternately
while (shorterList.Length() > 0)
{
shorterList.RemoveTop(tempCard);
InsertTop(tempCard);
longerList.RemoveTop(tempCard);
InsertTop(tempCard);
}
// Copy remainder of longer list to deck
while (longerList.Length() > 0)
{
longerList.RemoveTop(tempCard);
InsertTop(tempCard);
}
}
//****************************************************************** |
|
|
|
|
|