<html>

<head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Population</title>
</head>

<body>



<p align="center"><span lang="en-ca"><font size="6" color="#FF0000"><b>Shuffle</b></font></span></p>

<div align="left">
  <pre><b><font color="#ff0000" size="5">A.<span lang="en-ca">First</span> Edition</font></b></pre>
</div>
<div align="left">
  <pre><b>This is <span lang="en-ca">my first edition of assignment of shuffle which is quite different from <a href="Poke.htm">what I write by myself before</a></span> </b></pre>
</div>
<div align="left">
  <pre><b>which is a dealing program<span lang="en-ca">.</span></b></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">B</span>.<span lang="en-ca"><a name="problem"></a>The problem</span></font></b></pre>
</div>
<div align="left">
  <pre><b>T</b><span lang="en-ca"><b>he problem is to use the methods specified in the base abstract class List which implemented in two derived class</b></span></pre>
  <pre><span lang="en-ca"><b>---AList, LList. They are array-based and linklist-based implementation class. </b></span></pre>
  <pre>กก</pre>
</div>
<div align="left">
  <b><font color="#ff0000" size="5"><span lang="en-ca">C</span>.<span lang="en-ca">The
  </span></font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>idea of 
  program</b></font></span></div>
<div align="left">
  <pre><b>//program features:
//1. The header file given by book has one problem, that is, the AList.h and LList.h
//	 both has a &quot;DefaultListSize&quot; as default parameter for constructor which is not
//	 defined in their abastract base class----List. So, I arbitrarily add 
//	 const int DefaultListSize = 52 in List.h.
//2. In order for a better representation, I defined a helper class &quot;Card&quot; which stores 
//	 the suit and value information of a card. Since the List &quot;print&quot; function will use
//	 &quot;cout&lt;&lt;element&quot; to printout element. This Card class has implement a friend function
//	 to overload operator &lt;&lt;. And because I use pointer &quot;Card*&quot; instead of object &quot;Card&quot;
//	 as element in AList and LList, I have to overload &quot;ostream&amp; operator&lt;&lt;(ostream&amp;, Card*)&quot;.
//3. Shuffle is the major class to handle shuffling. Its private data includes both AList and
//	 LList lists. Basically I need to four lists to do shuffling:
//		a) a source list, which stores the original data to be shuffled.
//		b) a target list, which stores the result data.
//		c) one left and one right list to store the left and right half of source list.
//	 Since AList and LList are all inherited from List, I can use base class pointer to 
//	 do the same job. So I also need four pointer of List:
//		a) a pointer pointing to source list---pSource;
//		b) a pointer pointing to target list---pTarget;
//		c) two pointer pointing to left and right list---pLeft, pRight;
//4. Within the Shuffle there is a Card array cards[52] which stores all 52 cards. The List
//	 don't have to store the Card object itself, instead store its pointer Card*. So my AList
//	 and LList is of type of AList&lt;Card*&gt; and LList&lt;Card*&gt;. Suppose this element Card is a 
//	 complicated class with many data inside, its pointer will be much lighter to store.
//5. In the main function, I simply pass a flag to indicate whether I need to use array-based
//	 List or LinkList-based List implementation to function &quot;shuffling(ListType theType);&quot;. 
//	 All other code don't have to modify and it will output almost same with different List
//	 implementation to indicate that my program is implementation independent! So, the input
//	 of program is as simple as changing a single parameter in main function and call the 
//	 function &quot;shuffling&quot; again which will automatically initialize and doShuffle.
//6. function &quot;shuffling&quot; will call function &quot;doShuffle&quot; several times before it initialize 
//	 all parameters and divide the original source list into &quot;left&quot; and &quot;right&quot; by copying.
//7. function &quot;doShuffle&quot; is using base class pointer, so it is totally List-implementation-
//	 independent which means the code is uniform disregarding the type of List.
/////////////////////////////////////////////////////////////////////////////////////////////</b></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5">D.<span lang="en-ca"><a name="Method"></a>The </span>major functions</font></b></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">C</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>Further improvement</b></font></span></pre>
</div>
<div align="left">
  <pre>กก</pre>
</div>
<div align="left">
  <pre><b><font color="#FF0000"><span lang="en-ca">//List.h The base abstract class</span></font></b></pre>
</div>
<pre>#ifndef LIST_H
#define LIST_H
// List abstract class
const int DefaultListSize=52;
template &lt;class Elem&gt; class List {
public:
  // Reinitialize the list.  The client is responsible for
  // reclaiming the storage used by the list elements.
  virtual void clear() = 0;
  // Insert an element at the front of the right partition.
  // Return true if successful, false if the list is full.
  virtual bool insert(const Elem&amp;) = 0;
  // Append an element at the end of the right partition.
  // Return true if successful, false if the list is full.
  virtual bool append(const Elem&amp;) = 0;
  // Remove the first element of right partition. Return
  // true if successful, false if right partition is empty.
  // The element removed is returned in the parameter.
  virtual bool remove(Elem&amp;) = 0;
  // Place fence at list start, making left partition empty
  virtual void setStart() = 0;
  // Place fence at list end, making right partition empty
  virtual void setEnd() = 0;
  // Move fence one step left; no change if already at start
  virtual void prev() = 0;
  // Move fence one step right; no change if already at end
  virtual void next() = 0;
  // Return length of left partition
  virtual int leftLength() const = 0;
  // Return length of right partition
  virtual int rightLength() const = 0;
  // If pos or more elements are in the list, set the size
  // of left partition to pos and return true.  Otherwise,
  // do nothing and return false.
  virtual bool setPos(int pos) = 0;
  // Return in first parameter the first element  of the
  // right partition.  Return true if successful, false
  // if the right partition is empty.
  virtual bool getValue(Elem&amp;) const = 0;
  // Print the contents of the list
  virtual void print() const = 0;
};

#endif</pre>
<pre>กก</pre>
<pre><b><font color="#FF0000"><span lang="en-ca">//AList.h  The array-based derived class</span></font></b></pre>
<pre>#ifndef ALIST_H
#define ALIST_H

// This is the file to include in your code if you want access to the
// complete AList template class

// First, get the declaration for the base list class
#include &quot;list.h&quot;

template &lt;class Elem&gt; // Array-based list implementation
class AList : public List&lt;Elem&gt; {
private:
  int maxSize;        // Maximum size of list
  int listSize;       // Actual number of elements in list
  int fence;          // Position of fence
  Elem* listArray;    // Array holding list elements
public:
  AList(int size=DefaultListSize) { // Constructor
    maxSize = size;
    listSize = fence = 0;
    listArray = new Elem[maxSize];
  }
  ~AList() { delete [] listArray; } // Destructor
  void clear() {
    delete [] listArray;
    listSize = fence = 0;
    listArray = new Elem[maxSize];
  }
  bool insert(const Elem&amp;);
  bool append(const Elem&amp;);
  bool remove(Elem&amp;);
  void setStart() { fence = 0; }
  void setEnd()   { fence = listSize; }
  void prev()     { if (fence != 0) fence--; }
  void next()     { if (fence &lt;= listSize) fence++; }
  int leftLength() const  { return fence; }
  int rightLength() const { return listSize - fence; }
  bool setPos(int pos) {
    if ((pos &gt;= 0) &amp;&amp; (pos &lt;= listSize)) fence = pos;
    return (pos &gt;= 0) &amp;&amp; (pos &lt;= listSize);
  }
  bool getValue(Elem&amp; it) const {
    if (rightLength() == 0) return false;
    else { it = listArray[fence]; return true; }
  }
  void print() const {
    int temp = 0;
    cout &lt;&lt; &quot;&lt; &quot;;
    while (temp &lt; fence) cout &lt;&lt; listArray[temp++] &lt;&lt; &quot; &quot;;
    cout &lt;&lt; &quot;| &quot;;
    while (temp&lt;listSize) cout &lt;&lt; listArray[temp++] &lt;&lt; &quot; &quot;;
    cout &lt;&lt; &quot;&gt;\n&quot;;
  }
};

template &lt;class Elem&gt; // Insert at front of right partition
bool AList&lt;Elem&gt;::insert(const Elem&amp; item) {
  if (listSize == maxSize) return false; // List is full
  for(int i=listSize; i&gt;fence; i--)      // Shift Elems up
    listArray[i] = listArray[i-1];       //   to make room
  listArray[fence] = item;
  listSize++;                       // Increment list size
  return true;
}

template &lt;class Elem&gt; // Append Elem to end of the list
bool AList&lt;Elem&gt;::append(const Elem&amp; item) {
  if (listSize == maxSize) return false;
  listArray[listSize++] = item;
  return true;
}

// Remove and return first Elem in right partition
template &lt;class Elem&gt; bool AList&lt;Elem&gt;::remove(Elem&amp; it) {
  if (rightLength() == 0) return false; // Nothing in right
  it = listArray[fence];                // Copy removed Elem
  for(int i=fence; i&lt;listSize-1; i++)   // Shift them down
    listArray[i] = listArray[i+1];
  listSize--;                           // Decrement size
  return true;
}

#endif</pre>
<pre><b><font color="#FF0000"><span lang="en-ca">//Link.h  A helper class for linklist</span></font></b></pre>
<pre>#ifndef LINK_H
#define LINK_H

// Singly-linked list node
template &lt;class Elem&gt; class Link {
public:
  Elem element;      // Value for this node
  Link *next;        // Pointer to next node in list
  Link(const Elem&amp; elemval, Link* nextval =NULL)
    { element = elemval;  next = nextval; }
  Link(Link* nextval =NULL) { next = nextval; }
};
#endif</pre>
<pre><b><font color="#FF0000"><span lang="en-ca">//LList.h Linklist-based derived class</span></font></b></pre>
<pre>#ifndef LLIST_H
#define LLIST_H

// This is the file to include in your code if you want access to the
// complete LList template class

// First, get the declaration for the base list class
#include &quot;list.h&quot;

// Linked list implementation
template &lt;class Elem&gt; class LList: public List&lt;Elem&gt; {
private:
  Link&lt;Elem&gt;* head;       // Pointer to list header
  Link&lt;Elem&gt;* tail;       // Pointer to last Elem in list 
  Link&lt;Elem&gt;* fence;      // Last element on left side
  int leftcnt;            // Size of left partition
  int rightcnt;           // Size of right partition
  void init() {           // Intialization routine
    fence = tail = head = new Link&lt;Elem&gt;;
    leftcnt = rightcnt = 0;
  }
  void removeall() {   // Return link nodes to free store
    while(head != NULL) {
      fence = head;
      head = head-&gt;next;
      delete fence;
    }
  }
public:
  LList(int size=DefaultListSize) { init(); }
  ~LList() { removeall(); }  // Destructor
  void clear() { removeall(); init(); }
  bool insert(const Elem&amp;);
  bool append(const Elem&amp;);
  bool remove(Elem&amp;);
  void setStart()
    { fence = head; rightcnt += leftcnt; leftcnt = 0; }
  void setEnd()
    { fence = tail; leftcnt += rightcnt; rightcnt = 0; }
  void prev();
  void next() {
    if (fence != tail) // Don't move fence if right empty
      { fence = fence-&gt;next; rightcnt--; leftcnt++; }
  }
  int leftLength() const  { return leftcnt; }
  int rightLength() const { return rightcnt; }
  bool setPos(int pos);
  bool getValue(Elem&amp; it) const {
    if(rightLength() == 0) return false;
    it = fence-&gt;next-&gt;element;
    return true;
  }
  void print() const;
};

template &lt;class Elem&gt; // Insert at front of right partition
bool LList&lt;Elem&gt;::insert(const Elem&amp; item) {
  fence-&gt;next = new Link&lt;Elem&gt;(item, fence-&gt;next);  
  if (tail == fence) tail = fence-&gt;next;  // New tail
  rightcnt++;
  return true;
}

template &lt;class Elem&gt; // Append Elem to end of the list
bool LList&lt;Elem&gt;::append(const Elem&amp; item) {
  tail = tail-&gt;next = new Link&lt;Elem&gt;(item, NULL);
  rightcnt++;
  return true;
}

// Remove and return first Elem in right partition
template &lt;class Elem&gt; bool LList&lt;Elem&gt;::remove(Elem&amp; it) {
  if (fence-&gt;next == NULL) return false; // Empty right
  it = fence-&gt;next-&gt;element;       // Remember value
  Link&lt;Elem&gt;* ltemp = fence-&gt;next; // Remember link node
  fence-&gt;next = ltemp-&gt;next;       // Remove from list
  if (tail == ltemp) tail = fence; // Reset tail
  delete ltemp;                    // Reclaim space
  rightcnt--;
  return true;
}

// Move fence one step left; no change if left is empty
template &lt;class Elem&gt; void LList&lt;Elem&gt;::prev() {
  Link&lt;Elem&gt;* temp = head;
  if (fence == head) return; // No previous Elem
  while (temp-&gt;next!=fence) temp=temp-&gt;next;
  fence = temp;
  leftcnt--; rightcnt++;
}

// Set the size of left partition to pos
template &lt;class Elem&gt; bool LList&lt;Elem&gt;::setPos(int pos) {
  if ((pos &lt; 0) || (pos &gt; rightcnt+leftcnt)) return false;
  fence = head;
  for(int i=0; i&lt;pos; i++) fence = fence-&gt;next;
  return true;
}

template &lt;class Elem&gt; void LList&lt;Elem&gt;::print() const {
  Link&lt;Elem&gt;* temp = head;
  cout &lt;&lt; &quot;&lt; &quot;;
  while (temp != fence) {
    cout &lt;&lt; temp-&gt;next-&gt;element &lt;&lt; &quot; &quot;;
    temp = temp-&gt;next;
  }
  cout &lt;&lt; &quot;| &quot;;
  while (temp-&gt;next != NULL) {
    cout &lt;&lt; temp-&gt;next-&gt;element &lt;&lt; &quot; &quot;;
    temp = temp-&gt;next;
  }
  cout &lt;&lt; &quot;&gt;\n&quot;;
}

#endif</pre>
<pre><b><font color="#FF0000"><span lang="en-ca">//Shuffle.cpp  The implementation of shuffle class and driver program</span></font></b></pre>
<pre>//////////////////////////////////////////////////////
//program Name: Shuffle for assignment 2 of comp352 //
//file name: Shuffle.cpp                            //
//author: Qingzhe Huang                             //
//ID: 5037735                                       //
//date: Oct. 5, 2003                                //
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//program features:
//1. The header file given by book has one problem, that is, the AList.h and LList.h
//	 both has a &quot;DefaultListSize&quot; as default parameter for constructor which is not
//	 defined in their abastract base class----List. So, I arbitrarily add 
//	 const int DefaultListSize = 52 in List.h.
//2. In order for a better representation, I defined a helper class &quot;Card&quot; which stores 
//	 the suit and value information of a card. Since the List &quot;print&quot; function will use
//	 &quot;cout&lt;&lt;element&quot; to printout element. This Card class has implement a friend function
//	 to overload operator &lt;&lt;. And because I use pointer &quot;Card*&quot; instead of object &quot;Card&quot;
//	 as element in AList and LList, I have to overload &quot;ostream&amp; operator&lt;&lt;(ostream&amp;, Card*)&quot;.
//3. Shuffle is the major class to handle shuffling. Its private data includes both AList and
//	 LList lists. Basically I need to four lists to do shuffling:
//		a) a source list, which stores the original data to be shuffled.
//		b) a target list, which stores the result data.
//		c) one left and one right list to store the left and right half of source list.
//	 Since AList and LList are all inherited from List, I can use base class pointer to 
//	 do the same job. So I also need four pointer of List:
//		a) a pointer pointing to source list---pSource;
//		b) a pointer pointing to target list---pTarget;
//		c) two pointer pointing to left and right list---pLeft, pRight;
//4. Within the Shuffle there is a Card array cards[52] which stores all 52 cards. The List
//	 don't have to store the Card object itself, instead store its pointer Card*. So my AList
//	 and LList is of type of AList&lt;Card*&gt; and LList&lt;Card*&gt;. Suppose this element Card is a 
//	 complicated class with many data inside, its pointer will be much lighter to store.
//5. In the main function, I simply pass a flag to indicate whether I need to use array-based
//	 List or LinkList-based List implementation to function &quot;shuffling(ListType theType);&quot;. 
//	 All other code don't have to modify and it will output almost same with different List
//	 implementation to indicate that my program is implementation independent! So, the input
//	 of program is as simple as changing a single parameter in main function and call the 
//	 function &quot;shuffling&quot; again which will automatically initialize and doShuffle.
//6. function &quot;shuffling&quot; will call function &quot;doShuffle&quot; several times before it initialize 
//	 all parameters and divide the original source list into &quot;left&quot; and &quot;right&quot; by copying.
//7. function &quot;doShuffle&quot; is using base class pointer, so it is totally List-implementation-
//	 independent which means the code is uniform disregarding the type of List.
/////////////////////////////////////////////////////////////////////////////////////////////



#include &lt;iostream&gt;
#include &quot;LIST.H&quot;
#include &quot;ALIST.H&quot;
#include &quot;LINK.H&quot;
#include &quot;LLIST.H&quot;

using namespace std;

char* suitStr[4] = { &quot;Spade&quot;, &quot;Heart&quot;, &quot;Diamond&quot;, &quot;Club&quot;};

enum SuitName
{Spade, Heart, Diamond, Club};

enum ListType
{ArrayList, LinkList};

enum Position
{Left, Right};

//a helper class to denote the card value and suit
class Card
{
	//Card overload &quot;&lt;&lt;&quot; operator,
	// otherwise List member function &quot;print&quot; won't work!
	//PLS note the second parameter is pointer of Card: &quot;Card*&quot;
	friend ostream&amp; operator&lt;&lt;(ostream&amp; out, Card* card)
	{
		switch (card-&gt;value)
		{
		case 14:
			out&lt;&lt;&quot;Ace&quot;;
			break;
		case 13:
			out&lt;&lt;&quot;King&quot;;
			break;
		case 12:
			out&lt;&lt;&quot;Queen&quot;;
			break;
		case 11:
			out&lt;&lt;&quot;Jack&quot;;
			break;
		default:
			out&lt;&lt;card-&gt;value;
			break;
		}
		out&lt;&lt;&quot; &quot;&lt;&lt;suitStr[card-&gt;suit];
		return out;
	}
	
private:
	int suit;
	int value;
public:
	void setSuit(int theSuit) { suit = theSuit;}
	void setValue(int theValue) { value = theValue;}

};


class Shuffle
{
private:
	//this is the real card array and its pointers will be 
	//given to our List class
	Card cards[4][13];
	//these two generic base class pointer will do the same job
	//disregarding the implementation of array or linklist based.
	List&lt;Card*&gt;* pSource;
	List&lt;Card*&gt;* pTarget;
	//these two pointer represents the left-half and right-half
	List&lt;Card*&gt;* pLeft;
	List&lt;Card*&gt;* pRight;
	//array-based list
	//these are the left-half, right-half list
	AList&lt;Card*&gt; aLeft;
	AList&lt;Card*&gt; aRight;
	//these are the source and target list(array)
	AList&lt;Card*&gt; aSource;
	AList&lt;Card*&gt; aTarget;
	//link-list based list
	//these are the left-half, right-half list
	LList&lt;Card*&gt; lLeft;
	LList&lt;Card*&gt; lRight;
	//these are the source and target list(Linklist)
	LList&lt;Card*&gt; lSource;
	LList&lt;Card*&gt; lTarget;
	//param &quot;pos&quot; indicate whether remove from left or right,
	//return true if can remove, otherwise false
	bool getCard(Position pos);
	int getRand();
	void doShuffle(bool toShow=false);
	void initialize(ListType theType);
	void setParam(ListType theType);
	void divideList();
public:
	void shuffling(ListType theType=ArrayList);

};

int main()
{
	Shuffle S;
	cout&lt;&lt;&quot;First use array-based List to shuffle:\n&quot;;
	S.shuffling();
	cout&lt;&lt;&quot;\n\n\nSecond use linklist-based List to shuffle:\n\n&quot;;
	S.shuffling(LinkList);
	cout&lt;&lt;endl;
	return 0;
}

//param &quot;pos&quot; indicate whether remove from left or right,
//return true if can remove, otherwise false
bool Shuffle::getCard(Position pos)
{
	Card* card;//a pointer
	int number = getRand();
	List&lt;Card*&gt;* temp = pos==Left?pLeft:pRight;
	for (int i=0; i&lt;number; i++)
	{
		//remove one from left or right and 
		//insert into target
		if (temp-&gt;remove(card))
		{
			pTarget-&gt;insert(card);
		}
		else
		{
			return false;
		}
	}
	return true;
}

//divide source list into two halves and copy
//them into &quot;left&quot; and &quot;right&quot;
void Shuffle::divideList()
{
	Card* card;
	pSource-&gt;setPos(26);
	pLeft-&gt;setStart();
	pRight-&gt;setStart();
	while (pSource-&gt;remove(card))
	{
		//remove is from beginning, so we need append 
		pRight-&gt;append(card);
	}
	pSource-&gt;setStart();
	while (pSource-&gt;remove(card))
	{
		//append is efficient than insert generally
		pLeft-&gt;append(card);
	}
}

//this set up the pointers by param of ListType which
//indicate whether it is array or linklist
void Shuffle::setParam(ListType theType)
{
	switch (theType)
	{
	case ArrayList:
		pLeft = &amp;aLeft;
		pRight = &amp;aRight;
		pSource = &amp;aSource;
		pTarget = &amp;aTarget;
		break;
	case LinkList:
		pLeft = &amp;lLeft;
		pRight = &amp;lRight;
		pSource = &amp;lSource;
		pTarget = &amp;lTarget;
		break;
	}
}



//this function do the shuffle job, it first initialize 
//source according parameter &quot;ListType&quot;; Then shuffle 5 times
//in first time, call &quot;doShuffle&quot; with param of &quot;true&quot; to ask
//&quot;doShuffle&quot; to print intermidiate result.
void Shuffle::shuffling(ListType theType)
{
	List&lt;Card*&gt;* temp;
	initialize(theType);
	for (int i=0; i&lt;5; i++)
	{
		cout&lt;&lt;&quot;\nbefore no.&quot;&lt;&lt;i+1&lt;&lt;&quot; times shuffle:\n&quot;;
		pSource-&gt;print();
		if (i==0)
		{
			doShuffle(true);
		}
		else
		{
			doShuffle(false);
		}
		cout&lt;&lt;&quot;\nafter no.&quot;&lt;&lt;i+1&lt;&lt;&quot; times shuffle:\n&quot;;
		pTarget-&gt;print();
		//swap the two pointer so that shuffle again.
		temp = pSource;
		pSource= pTarget;
		pTarget = temp;
	}
}

//a utility method to get random number of 0-5
int Shuffle::getRand()
{
	return rand()%6;
}

//first divide source into two halves, copy them to pLeft and pRight
//alternatively remove random number of cards from two halves until both
//halves are empty
void Shuffle::doShuffle(bool toShow)
{
	bool leftEmpty=false, rightEmpty=false;
	int counter=0;
	divideList();
	if (toShow)
	{
		cout&lt;&lt;&quot;\nbefore getCard, left half is:\n&quot;;
		pLeft-&gt;print();
		cout&lt;&lt;&quot;\nbefore getCard, right half is:\n&quot;;
		pRight-&gt;print();
		cout&lt;&lt;&quot;\nbefore getCard, result is:\n&quot;;
		pTarget-&gt;print();
	}
	while ((!leftEmpty)||(!rightEmpty))
	{
		if (!getCard(Left))
		{
			leftEmpty= true;
		}
		if (!getCard(Right))
		{
			rightEmpty = true;
		}
		counter++;
		if (toShow)
		{
			cout&lt;&lt;&quot;\nafter &quot;&lt;&lt;counter&lt;&lt;&quot; times getCard, left half is:\n&quot;;
			pLeft-&gt;print();
			cout&lt;&lt;&quot;\nafter &quot;&lt;&lt;counter&lt;&lt;&quot; times getCard, right half is:\n&quot;;
			pRight-&gt;print();
			cout&lt;&lt;&quot;\nafter &quot;&lt;&lt;counter&lt;&lt;&quot; times getCard, result is:\n&quot;;
			pTarget-&gt;print();
		}
	}	
}
		
//initialize cards array and copy the standard card pointers into source.
void Shuffle::initialize(ListType theType)
{
	setParam(theType);
	for (int theSuit =0; theSuit&lt;4; theSuit++)
	{
		for (int theValue=0; theValue&lt;13; theValue++)
		{
			cards[theSuit][theValue].setSuit(theSuit);
			//the value of a card is starting from 14 till 2
			cards[theSuit][theValue].setValue(14-theValue);
			//as the element is Card*, we add pointers
			//and here the pSource is actually a base class pointer
			//disregarding it is array-based-list or link-list-based-list!
			pSource-&gt;append(&amp;cards[theSuit][theValue]);
		}
	}
}





</pre>
<pre>กก</pre>
<pre><span lang="en-ca"><a name="result"></a><font size="3" color="#FF0000">The result is like following:</font></span></pre>
<pre><span lang="en-ca"><font size="3" color="#FF0000">I omitted all intermediate result as it is too many, if you really like to check, <a href="shuffle.txt">click here</a>.</font></span></pre>
<pre><span lang="en-ca"><font size="3" color="#FF0000">......</font></span></pre>
<p>after no.1 times shuffle: </p>
<p>&lt; | 2 Club 3 Club 4 Club 5 Club 6 Club 7 Club 8 Club 9 Club 10 Club Jack Club 
Queen Club 2 Heart King Club Ace Club 2 Diamond 3 Diamond 3 Heart 4 Heart 5 
Heart 4 Diamond 5 Diamond 6 Diamond 7 Diamond 8 Diamond 6 Heart 7 Heart 8 Heart 
9 Heart 10 Heart Jack Heart Queen Heart King Heart Ace Heart 2 Spade 3 Spade 4 
Spade 5 Spade 6 Spade 7 Spade 8 Spade 9 Spade 9 Diamond 10 Diamond Jack Diamond 
10 Spade Jack Spade Queen Spade King Spade Ace Spade Queen Diamond King Diamond 
Ace Diamond &gt;<br>
<br>
<br>
</p>
<p>before no.2 times shuffle: </p>
<p>&lt; | 2 Club 3 Club 4 Club 5 Club 6 Club 7 Club 8 Club 9 Club 10 Club Jack Club 
Queen Club 2 Heart King Club Ace Club 2 Diamond 3 Diamond 3 Heart 4 Heart 5 
Heart 4 Diamond 5 Diamond 6 Diamond 7 Diamond 8 Diamond 6 Heart 7 Heart 8 Heart 
9 Heart 10 Heart Jack Heart Queen Heart King Heart Ace Heart 2 Spade 3 Spade 4 
Spade 5 Spade 6 Spade 7 Spade 8 Spade 9 Spade 9 Diamond 10 Diamond Jack Diamond 
10 Spade Jack Spade Queen Spade King Spade Ace Spade Queen Diamond King Diamond 
Ace Diamond &gt;<br>
<br>
<br>
</p>
<p>after no.2 times shuffle: </p>
<p>&lt; | 7 Heart 6 Heart 8 Diamond 7 Diamond 6 Diamond 5 Diamond 4 Diamond 5 Heart 
Ace Diamond 4 Heart King Diamond Queen Diamond Ace Spade King Spade Queen Spade 
3 Heart 3 Diamond 2 Diamond Ace Club King Club Jack Spade 10 Spade Jack Diamond 
2 Heart Queen Club Jack Club 10 Diamond 9 Diamond 9 Spade 8 Spade 7 Spade 10 
Club 6 Spade 5 Spade 4 Spade 9 Club 3 Spade 2 Spade Ace Heart King Heart Queen 
Heart 8 Club 7 Club 6 Club Jack Heart 10 Heart 9 Heart 8 Heart 5 Club 4 Club 3 
Club 2 Club &gt;<br>
<br>
<br>
</p>
<p>before no.3 times shuffle: </p>
<p>&lt; | 7 Heart 6 Heart 8 Diamond 7 Diamond 6 Diamond 5 Diamond 4 Diamond 5 Heart 
Ace Diamond 4 Heart King Diamond Queen Diamond Ace Spade King Spade Queen Spade 
3 Heart 3 Diamond 2 Diamond Ace Club King Club Jack Spade 10 Spade Jack Diamond 
2 Heart Queen Club Jack Club 10 Diamond 9 Diamond 9 Spade 8 Spade 7 Spade 10 
Club 6 Spade 5 Spade 4 Spade 9 Club 3 Spade 2 Spade Ace Heart King Heart Queen 
Heart 8 Club 7 Club 6 Club Jack Heart 10 Heart 9 Heart 8 Heart 5 Club 4 Club 3 
Club 2 Club &gt;<br>
<br>
<br>
</p>
<p>after no.3 times shuffle: </p>
<p>&lt; | Jack Club Queen Club 2 Heart Jack Diamond 10 Spade Jack Spade King Club 
Ace Club 2 Diamond 3 Diamond 3 Heart Queen Spade King Spade Ace Spade Queen 
Diamond King Diamond 2 Club 4 Heart 3 Club 4 Club 5 Club Ace Diamond 5 Heart 8 
Heart 9 Heart 10 Heart Jack Heart 6 Club 7 Club 8 Club Queen Heart King Heart 
Ace Heart 4 Diamond 5 Diamond 6 Diamond 7 Diamond 2 Spade 3 Spade 9 Club 4 Spade 
5 Spade 6 Spade 10 Club 7 Spade 8 Spade 9 Spade 9 Diamond 10 Diamond 8 Diamond 6 
Heart 7 Heart &gt;<br>
<br>
<br>
</p>
<p>before no.4 times shuffle: </p>
<p>&lt; | Jack Club Queen Club 2 Heart Jack Diamond 10 Spade Jack Spade King Club 
Ace Club 2 Diamond 3 Diamond 3 Heart Queen Spade King Spade Ace Spade Queen 
Diamond King Diamond 2 Club 4 Heart 3 Club 4 Club 5 Club Ace Diamond 5 Heart 8 
Heart 9 Heart 10 Heart Jack Heart 6 Club 7 Club 8 Club Queen Heart King Heart 
Ace Heart 4 Diamond 5 Diamond 6 Diamond 7 Diamond 2 Spade 3 Spade 9 Club 4 Spade 
5 Spade 6 Spade 10 Club 7 Spade 8 Spade 9 Spade 9 Diamond 10 Diamond 8 Diamond 6 
Heart 7 Heart &gt;<br>
<br>
<br>
</p>
<p>after no.4 times shuffle: </p>
<p>&lt; | 10 Heart 9 Heart 8 Heart 5 Heart Ace Diamond 5 Club 7 Heart 6 Heart 4 
Club 3 Club 8 Diamond 10 Diamond 9 Diamond 4 Heart 2 Club King Diamond Queen 
Diamond 9 Spade 8 Spade Ace Spade 7 Spade 10 Club 6 Spade 5 Spade 4 Spade King 
Spade Queen Spade 9 Club 3 Spade 2 Spade 3 Heart 3 Diamond 2 Diamond Ace Club 
King Club 7 Diamond 6 Diamond Jack Spade 10 Spade Jack Diamond 2 Heart Queen 
Club 5 Diamond 4 Diamond Ace Heart King Heart Jack Club Queen Heart 8 Club 7 
Club 6 Club Jack Heart &gt;<br>
<br>
<br>
</p>
<p>before no.5 times shuffle: </p>
<p>&lt; | 10 Heart 9 Heart 8 Heart 5 Heart Ace Diamond 5 Club 7 Heart 6 Heart 4 
Club 3 Club 8 Diamond 10 Diamond 9 Diamond 4 Heart 2 Club King Diamond Queen 
Diamond 9 Spade 8 Spade Ace Spade 7 Spade 10 Club 6 Spade 5 Spade 4 Spade King 
Spade Queen Spade 9 Club 3 Spade 2 Spade 3 Heart 3 Diamond 2 Diamond Ace Club 
King Club 7 Diamond 6 Diamond Jack Spade 10 Spade Jack Diamond 2 Heart Queen 
Club 5 Diamond 4 Diamond Ace Heart King Heart Jack Club Queen Heart 8 Club 7 
Club 6 Club Jack Heart &gt;<br>
<br>
<br>
</p>
<p>after no.5 times shuffle: </p>
<p>&lt; | King Spade 4 Spade 5 Spade 6 Spade 10 Club Jack Heart 6 Club 7 Club 8 
Club 7 Spade Ace Spade Queen Heart Jack Club King Heart Ace Heart 8 Spade 9 
Spade Queen Diamond King Diamond 4 Diamond 2 Club 5 Diamond Queen Club 4 Heart 9 
Diamond 10 Diamond 8 Diamond 3 Club 2 Heart Jack Diamond 10 Spade Jack Spade 6 
Diamond 4 Club 6 Heart 7 Diamond King Club 7 Heart 5 Club Ace Club 2 Diamond 3 
Diamond 3 Heart 2 Spade Ace Diamond 5 Heart 8 Heart 9 Heart 3 Spade 9 Club Queen 
Spade 10 Heart &gt;<br>
<br>
<br>
</p>

<pre></pre>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                   
&nbsp;&nbsp;&nbsp; <a href="WhoAmI.htm">                  







                       <img src="picture/back.gif" style="border: medium none" alt="back.gif (341 bytes)" width="32" height="35"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="index.htm"><img src="picture/up.gif" style="border: medium none" alt="up.gif (335 bytes)" width="35" height="32"></a>       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                         
<img src="picture/next.gif" style="border: medium none" alt="next.gif (337 bytes)" width="32" height="35">          


</p>

</body>

</html>