TEST/자료구조와 함께 배우는 알고리즘 입문(C언어)
<2> Q10. 자료구조와 함께 배우는 알고리즘 입문 (C언어)
도라몬즈
2020. 6. 28. 23:19
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void shuffle(int a[], int n)
{
srand(time(NULL));
int temp;
int r;
for (int i = 0; i < n; i++) {
temp = a[i];
r = rand() % n;
a[i] = a[r];
a[r] = temp;
}
}
int main(void)
{
int a[] = { 0,1,2,3,4,5,6,7,8 };
shuffle(a, 9);
for (int i = 0; i < 9; i++)
printf("a[%d] = %d\n", i, a[i]);
return 0;
}