From 3edf158e21a4ab52aa4d356be783003d22f2b26a Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Tue, 12 Jan 2021 13:19:46 +0530 Subject: [PATCH] Added bubble sort algorithm in C++ --- SORTING/C++/bubble_sort.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 SORTING/C++/bubble_sort.cpp diff --git a/SORTING/C++/bubble_sort.cpp b/SORTING/C++/bubble_sort.cpp new file mode 100644 index 00000000..fb80422f --- /dev/null +++ b/SORTING/C++/bubble_sort.cpp @@ -0,0 +1,33 @@ +//bubble sort +# include +using namespace std; + +int main() +{ + cout<<"Enter the length of array"<>n; + int arr[n]; + cout<<"Enter the elements of array"<>arr[i]; + } + for (int i = 0; i < n; i++) + { + for (int j= 0; j< n-1; j++) + { //comparing adjecent elements of array + if (arr[j]>arr[j+1]) + { // swaping array elements + temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + } + for (int i = 0; i < n; ++i) + { + cout<