Bubble_ Select_ Sort
# include <stdio.h>
# include <stdbool.h>
# include <stdlib.h>
# define LENGTH 9
//________________________________
void Do_bubble_sort_(int[]);
void Do_select_sort_(int[]);
void Do_merge_sort_(int[]);
//________________________________
int main(void) {
int Arry[] = { 30, 15, 16, 24, 36, 33, 17, 29, 32 };
//Do_bubble_sort_(Arry);
Do_select_sort_(Arry);
return 0;
} // end of main function
//________________________________
void Do_bubble_sort_(int param[]) {
char f_num_to_string[3] = { 0, };
int Tmp = 0x0;
bool res;
FILE *F;
F = fopen("bubble.txt", "w");
fprintf(F, "bubble.sort.step\n");
for (int i = 0; i < LENGTH - 1; i++) {
res = false;
fprintf(F, itoa(i+1, f_num_to_string, 10));
fprintf(F, "\n");
for (int j = 0; j < LENGTH - 1; j++) {
if (param[j] > param[j + 1]) {
Tmp = param[j];
param[j] = param[j + 1];
param[j + 1] = Tmp;
res = true;
// 메모장 입력 _start ====================================
for (int k = 0; k < LENGTH; k++) {
fprintf(F, itoa(param[k], f_num_to_string, 10));
fprintf(F, "\t");
}
fprintf(F, "\n");
// 메모장 입력 _end ======================================
}
}
if (res == false) {
break;
}
}
fclose(F);
for (int j = 0; j < LENGTH; j++) {
printf("%d", param[j]);
if (j != LENGTH - 1) {
printf(" ");
}
}printf("\n");
} // end of Do_bubble_sort_ function
//________________________________
void Do_select_sort_(int param[]) {
char f_num_to_string[3] = { 0, };
int i, j, k; // index
int Tmp = 0x0;
int small = 0x0;
bool res;
FILE *F;
F = fopen("selectSort.txt", "w");
fprintf(F, "select.sort.step\n");
for (i = 0; i < LENGTH-1; i++) {
res = false;
small = param[i];
for (j = i + 1; j < LENGTH; j++) {
if (param[j] < small) {
Tmp = param[i];
param[i] = param[j];
param[j] = Tmp;
small = param[i];
res = true;
// 메모장 입력 _start ====================================
for (k = 0; k < LENGTH; k++) {
fprintf(F, itoa(param[k], f_num_to_string, 10));
fprintf(F, "\t");
}
fprintf(F, "\n");
// 메모장 입력 _end ======================================
}
}
if (res == false) {
break;
}
}
fclose(F);
for (j = 0; j < LENGTH; j++) {
printf("%d", param[j]);
if (j != LENGTH - 1) {
printf(" ");
}
}printf("\n");
} // end of Do_select_sort_ function
//________________________________
void Do_merge_sort_(int param[]) {
} // end of Do_merge_sort_ function