-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbleShort.cpp
More file actions
35 lines (27 loc) · 781 Bytes
/
bubbleShort.cpp
File metadata and controls
35 lines (27 loc) · 781 Bytes
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
26
27
28
29
30
31
32
33
34
35
#include <iostream>
void bubbleSort(int arr[], int size);
void printArray(int arr[], int size);
int main() {
int numbers[] = {5, 3, 8, 4, 2, 1, 6, 7, 9, 10};
int size = sizeof(numbers) / sizeof(numbers[0]);
printArray(numbers, size);
bubbleSort(numbers, size);
printArray(numbers, size);
}
void bubbleSort(int arr[], int size) {
for(int i = 0; i < size - 1; i++) {
for(int j = 0; j < size - 1 - i; j++) {
if(arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
std::cout << arr[i] << " ";
}
std::cout << std::endl;
}