C언어로 버블 정렬 구현하기
by 으렴구현 해봄
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<stdio.h> int mian(){ int numArr[10] = { 10,5,6,8,3,2,4,1,9,7 }; bubble_sort(numArr, sizeof(numArr) / sizeof(int)); for(int i = 0 ; i < 10 ; i++){ printf("%d , ",numArr[i]); } printf("\n"); return 0; } void bubble_sort(int arr[], int count){ int temp; for(int i =0 ; i<count ; i++){ //요소 개수 만큼 반복 for(int j=0;j<count-1; j++) { if(arr[j] >arr[j+1]){ //temp 바꾸기; temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } } | cs |
요소 개수만큼 반복하게 만들고 템프로 바꿔주면 끝!
'Programming Language > C and Cpp' 카테고리의 다른 글
C언어 배열과 포인터 문제 (0) | 2019.05.17 |
---|---|
C++ String 구현 해 보기 (0) | 2019.02.21 |
C++ 복사 생성자 (0) | 2018.03.16 |
C++ DAY5 Is-a관계 (0) | 2018.03.14 |
C++ DAY4 const (0) | 2018.03.08 |
사이트의 정보
코딩하렴
으렴