From 3beb4a26747ceae03abfb381148309e9927148df Mon Sep 17 00:00:00 2001 From: foxliver Date: Sat, 11 Oct 2025 16:06:47 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B0=EC=97=B4=EC=9D=84=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20BubbleSort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Array/bubbleSort.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Array/bubbleSort.c diff --git a/Array/bubbleSort.c b/Array/bubbleSort.c new file mode 100644 index 0000000..46e2c6e --- /dev/null +++ b/Array/bubbleSort.c @@ -0,0 +1,52 @@ +#include +#include +#include + +#define SIZE 20 + +int is_duplicate(int arr[], int size, int value); + +int main() { + int value[SIZE]; + srand((unsigned)time(NULL)); + + printf("정렬 전 ["); + int count = 0; + while(count < SIZE){ + // 0 ~ 99 + int num = rand() % 100; + if(!is_duplicate(value, count, num)){ + value[count] = num; + printf(" %02d ", value[count]); + count++; + } + } + printf("]\n"); + + for(int i = 0; i < SIZE - 1; i++){ + for(int j = 0; j < SIZE - i - 1; j++){ + if(value[j] > value[j + 1]){ + int tmp = value[j]; + value[j] = value[j + 1]; + value[j + 1] = tmp; + } + } + } + + printf("정렬 후 ["); + for(int i = 0; i < SIZE; i++){ + printf(" %02d ", value[i]); + } + printf("]\n"); + + + return 0; +} + +int is_duplicate(int arr[], int size, int value){ + for(int i = 0; i < size; i++){ + if(arr[i] == value){ return 1; } + } + + return 0; +}