diff --git a/Cpp/simple_bubble_sort.cpp b/Cpp/simple_bubble_sort.cpp new file mode 100644 index 0000000..519277a --- /dev/null +++ b/Cpp/simple_bubble_sort.cpp @@ -0,0 +1,35 @@ +#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]) { + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } +} + +int main() { + int arr[] = {5, 3, 8, 4, 2}; + int n = 5; + + cout << "Original array: "; + for (int i = 0; i < n; i++) { + cout << arr[i] << " "; + } + cout << endl; + + bubbleSort(arr, n); + + cout << "Sorted array: "; + for (int i = 0; i < n; i++) { + cout << arr[i] << " "; + } + cout << endl; + + return 0; +}