#include <_stdio.h_>
#include <_stdlib._h>
#include <_time._h>
#define MAX 52
void get_card( int *add );
void sort_card(int *add );//bubble sort
int main() {
int i = 0; //i=第幾張牌
int card[MAX]={0}; //[0、、、51]
get_card( card ); //傳送card 位址給 get_card()
for( i=0; i< MAX; i++ ) {
if ( i % 10 == 0) printf( "\n" ); //10張就斷行
printf( "-,", card[i]); // 0 用空白取代
}
printf( "\n----------------------\n" );
sort_card( card ); //傳送card 位址給 sort_card()
for( i=0; i< MAX; i++ ) {
if ( i % 10 == 0) printf( "\n" ); //10張就斷行
printf( "-,", card[i]); // 0 用空白取代
}
printf( "\n----------------------\n" );
return 0;
}
//--------------------------------------------
void sort_card( int *add ) {
int i, j, temp;
for (i=MAX; i>1; i-- ){
for ( j=0; j
if ( add[j] > add[j+1]) { //若左邊大於右邊
temp = add[j]; //temp = 左邊
add[j] = add[j+1]; //左邊=右邊
add[j+1] = temp; //右邊=temp
}
}
}
}
//--------------------------------------------
void get_card( int *add ) {
int done[MAX] = {0}, busy = 1;
int i = 0; //i=發到第幾張牌
srand( time(NULL) ); //clock() );
while ( 1 ) {
busy = 1; //預設一直抓
while ( busy ) {
int n = rand() % MAX ; // (0~51) + 1 = 1~52
if ( done[n] == 0 ) { //判斷這張牌 有沒有 發過??
done[n] = 1; //表示這張牌已被使用
add[i] = n; //發出去這張牌
busy = 0;
}
}
if ( ++i >= MAX ) break;
}
}