버블 정렬 : 옆에 있는 값을 비교해서 큰값을 뒤로 보내는 과정을 반복하는 정렬입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
int main()
{
int array[10] = { 1, 9, 4, 10, 6, 2, 5, 3, 7, 8 };
int temp;
for(int i = 0; i < 10; ++i)
{
for (int j = 0; j < 9-i; j++)
{
if (array[j] > array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
return 0;
}
|
'스터디 > 자료구조' 카테고리의 다른 글
[ 자료구조 ] Quick sort (0) | 2020.02.23 |
---|---|
[ 자료구조 ] Insertion sort (0) | 2020.02.23 |
[ 자료구조 ] Selection Sort (0) | 2020.02.23 |
[ 자료구조 ] Binary Search Tree (0) | 2020.02.23 |
[ 자료구조 ] Deque (0) | 2020.02.22 |