From 6205f1ab64285f4ebb391f1058d483849dc6b28d Mon Sep 17 00:00:00 2001 From: vinaya563 <91210199+vinaya563@users.noreply.github.com> Date: Sat, 2 Oct 2021 08:23:18 +0530 Subject: [PATCH] Create bubble sort --- CPP/bubble sort | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 CPP/bubble sort diff --git a/CPP/bubble sort b/CPP/bubble sort new file mode 100644 index 0000000..5290b56 --- /dev/null +++ b/CPP/bubble sort @@ -0,0 +1,41 @@ +#include +using namespace std; +void swapping(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i array[j+1]) { + swapping(array[j], array[j+1]); + swaps = 1; + } + } + if(!swaps) + break; + } +} +int main() { + int n; + cout << "Enter the number of elements: "; + cin >> n; + int arr[n]; + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + bubbleSort(arr, n); + cout << "Array after Sorting: "; + display(arr, n); +}