diff --git a/application of algorithm/bubble_sort.cpp b/application of algorithm/bubble_sort.cpp new file mode 100644 index 0000000..7697125 --- /dev/null +++ b/application of algorithm/bubble_sort.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +void bubbleSort(int arr[], int n) { + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < n - i - 1; j++) { + if (arr[j] > arr[j + 1]) + swap(arr[j], arr[j + 1]); + } + } +} + +int main() { + int arr[] = {5, 3, 8, 4, 2}; + int n = 5; + + bubbleSort(arr, n); + + cout << "Sorted array: "; + for (int x : arr) cout << x << " "; +}