//bubble sort
//2016 2 17
//kim jun hyeon
//ver 1.0
#include <stdio.h>
#define SIZE 10
void bubble_sorting(int[]);
int main(void) {
 int arr_int[SIZE] = { 0, }; // initiallize
 int index;
 for (index = 0; index < SIZE; index++) {
  printf("arr_int[%d] data input >>> ", index);
  scanf_s("%d", &arr_int[index]);
 }
 bubble_sorting(arr_int);
 return 0;
}
void bubble_sorting(int arr[])
{
 int indexI, indexJ, indexK;
 int temp = 0;
 for (indexI = 0; indexI < SIZE-1; indexI++){
  for (indexJ = 0; indexJ <SIZE-1; indexJ++){
   if (arr[indexJ] > arr[indexJ + 1]) {
    temp = arr[indexJ];
    arr[indexJ] = arr[indexJ + 1];
    arr[indexJ + 1] = temp;
    for (indexK = 0; indexK < SIZE; indexK++) {
     printf("%d ", arr[indexK]);
    }printf("\n");
   }
  }
 }
 for (indexK = 0; indexK < SIZE; indexK++) {
  printf("%d ", arr[indexK]);
 }printf("\n");
}

'언어 > c언어' 카테고리의 다른 글

QUEUE  (0) 2016.02.22
STACK  (0) 2016.02.21
queue (수정할것 아직 완성되지 않음)  (0) 2016.02.17
linkedList (수정)  (0) 2016.02.16
naver 지식인  (0) 2016.02.15