CiscoKid
04-29-03, 10:54 AM
Working on my C homework and hit a brick wall...
What's the best way to sort elements of an array?
the code I have so is:
/*
Assignment 6
Lopez, Enrique 1031
4/21/2003
Edit fig. 7.24 so that:
a five card poker hand is drawn
a) Determin if the hand contains a pair
b) Determin if the hand contains two pairs
c) Determin if the hand contains three of a kind (e.g., three jacks)
d) Determin if the hand contains four of a kind (e.g., four aces)
e) Determin if the hand contains a flush (i.e., all five cards of the same suit)
f) Determin if the hand contains a straight (i.e., five cards of consecutive face values)
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
void shuffle( int [][ 13 ] );
void deal( const int [] [ 13 ], const char *[], const char *[] );
int main()
{
const char *suit[ 4 ] =
{ "Hearts", "Diamonds", "Clubs", "Spades" };
const char *face[ 13 ] =
{ "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
int deck[ 4 ] [ 13 ] = { 0 };
srand( time( 0 ) );
shuffle( deck );
deal( deck, face, suit );
return 0;
}
void shuffle( int wDeck[][ 13 ] )
{
int row, column, card;
for ( card = 1; card <= 52; card++ ) {
do
{
row = rand() % 4;
column = rand() % 13;
} while(wDeck[ row ][ column ] != 0);
wDeck[ row][ column ] = card;
}
}
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int card, row, column;
for ( card = 1; card <= 5; card++ )
for ( row = 0; row <= 3; row++ )
for ( column = 0; column <= 12; column++ )
if (wDeck[ row ][ column ] == card )
printf( "%5s of %-8s%c",
wFace[ column ], wSuit[ row ],
card % 1 == 0 ? '\n' : '\t' );
void pair();
}
void pair()
{
}
my instructor told me the best way to do it is to sort the array then cmpare the elements, what would be the best way to do this?
What's the best way to sort elements of an array?
the code I have so is:
/*
Assignment 6
Lopez, Enrique 1031
4/21/2003
Edit fig. 7.24 so that:
a five card poker hand is drawn
a) Determin if the hand contains a pair
b) Determin if the hand contains two pairs
c) Determin if the hand contains three of a kind (e.g., three jacks)
d) Determin if the hand contains four of a kind (e.g., four aces)
e) Determin if the hand contains a flush (i.e., all five cards of the same suit)
f) Determin if the hand contains a straight (i.e., five cards of consecutive face values)
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
void shuffle( int [][ 13 ] );
void deal( const int [] [ 13 ], const char *[], const char *[] );
int main()
{
const char *suit[ 4 ] =
{ "Hearts", "Diamonds", "Clubs", "Spades" };
const char *face[ 13 ] =
{ "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
int deck[ 4 ] [ 13 ] = { 0 };
srand( time( 0 ) );
shuffle( deck );
deal( deck, face, suit );
return 0;
}
void shuffle( int wDeck[][ 13 ] )
{
int row, column, card;
for ( card = 1; card <= 52; card++ ) {
do
{
row = rand() % 4;
column = rand() % 13;
} while(wDeck[ row ][ column ] != 0);
wDeck[ row][ column ] = card;
}
}
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int card, row, column;
for ( card = 1; card <= 5; card++ )
for ( row = 0; row <= 3; row++ )
for ( column = 0; column <= 12; column++ )
if (wDeck[ row ][ column ] == card )
printf( "%5s of %-8s%c",
wFace[ column ], wSuit[ row ],
card % 1 == 0 ? '\n' : '\t' );
void pair();
}
void pair()
{
}
my instructor told me the best way to do it is to sort the array then cmpare the elements, what would be the best way to do this?