wex3_8.cpp

来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 72 行

CPP
72
字号
#include <iostream.h>
#pragma hdrstop

#include "wex3_8.h"

void Swap (int &x, int &y)
{
   int temp;
   
   temp = x;
   x = y;
   y = temp;
}

// order an integer array using the exchange sort
void Sort(int a[], int size)
{
   int i, j;
   
   for (i = 0; i < size-1; i++)
      for (j = i+1; j < size; j++)
         if (a[j] < a[i])
            Swap(a[j],a[i]);
}

// deal n cards from deck d
void DealHand(CardDeck& d, int n)
{
	int cards[52];
	
	// deal n cards and record them in array cards
	for(int i=0;i < n;i++)
		cards[i] = d.GetCard();
		
	// sort the card values
	Sort(cards,n);
	
	// print the card faces
	for(i=0;i < n;i++)
		d.PrintCard(cards[i]);
}

void main(void)
{
	CardDeck d;
	
	// deck is shuffled. deal a hand
	DealHand(d,5);
	cout << endl << endl;
	
	// shuffle again and deal
	d.Shuffle();
	DealHand(d,5);
}

/*
<Run>

6 of clubs
6 of diamonds
10 of diamonds
5 of hearts
Queen of hearts


King of clubs
3 of diamonds
King of diamonds
10 of hearts
Ace of spades
*/ 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?