본문 바로가기

TEST/자료구조와 함께 배우는 알고리즘 입문(C언어)

(73)
<6> Q8. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include void insertion(int a[], int n) { int i, j, k; for (i = 1; i 0 && a[j - 1] > tmp; j--) a[j] = a[j - 1]; a[j] = tmp; for (k = 0; k < j; k++) printf(" "); if (i != j){ printf("^"); }else { printf(" "); } for (k = j; k < i; k++) printf("---"); printf("+"); printf("\n"); } } i..
<6> Q7. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include #define swap(type,x,y)do{type t=x;x=y;y=t;}while(0) void selection(int a[],int n) { int i,j,k; for(i=0;i
<6> Q6. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include #define swap(type, x, y) \ do \ { \ type t = x; \ x = y; \ y = t; \ } while (0) void bubble(int a[], int n) { int k = 0, b = n - 1; while (k k; j--) if (a[j - 1] > a[j]) { swap(int, a[j - 1], a[j]); last = j; } k = last; for (j = k; j a[+1]) { swap(int, a[j], a[j + 1]); last = j + 1; } b = last; } } int main(void)..
<6> Q5. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include #define swap(type, x, y) \ do \ { \ type t = x; \ x = y; \ y = t; \ } while (0) void bubble(int a[], int n) { int i = 0, j, k; int compare = 0, change = 0; while (i i; j--) { for (k = 0; k a[j]) { printf("%3c", '+'); for (k = j; k < n; k++) printf("%3d", a[k]..
<6> Q4. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include #define swap(type, x, y) \ do \ { \ type t = x; \ x = y; \ y = t; \ } while (0) void bubble(int a[], int n) { int i, j, k; int compare = 0, change = 0, exchg = 0; for (i = 0; i i; j--) { for (k = 0; k a[j]) { printf("%3c", '+'); for (k = j; k < n; k++) printf("..
<6> Q3. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include #define swap(type, x, y) \ do \ { \ type t = x; \ x = y; \ y = t; \ } while (0) void bubble(int a[], int n) { int i, j; for(i=0;ii;j--) if(a[j-1]>a[j]){ swap(int ,a[j-1],a[j]); exchg++; } if(exchg==0)break; } } int is_sorted(const int a[],int n) { for(int i = 0; ia[i+1]) return 0; } return 1; } int main(void) { int i, nx; int *x; puts("버블 정렬"); printf("요소 개수 : "); scanf("%d", &..
<6> Q2. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include #define swap(type, x, y) \ do \ { \ type t = x; \ x = y; \ y = t; \ } while (0) void bubble(int a[], int n) { int i, j, k; int compare = 0, change = 0; for (i = 0; i i; j--) { for (k = 0; k a[j]) { printf("%3c", '+'); for (k = j; k < n; k++) printf("%3d", a[k]); swap(int,..
<6> Q1. 자료구조와 함께 배우는 알고리즘 입문 (C언어) #include #include #define swap(type, x, y) \ do \ { \ type t = x; \ x = y; \ y = t; \ } while (0) void bubble(int a[], int n) { int i, j; for (i = 0; i a[j + 1]) swap(int, a[j], a[j + 1]); } } int main(void) { int i, nx; int *x; puts("버블 정렬"); printf("요소 개수 : "); scanf("%d", &nx); x = calloc(nx, sizeof(int)); for (i = 0; i < nx; i++) { p..