From 0da469b04723350858a37f77f48a845313d21e75 Mon Sep 17 00:00:00 2001 From: Manvi07 Date: Tue, 2 Oct 2018 11:39:58 +0530 Subject: [PATCH] Added bubble sort in C++ --- Sorting/bubbleSort/bubble_sort.cpp | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Sorting/bubbleSort/bubble_sort.cpp diff --git a/Sorting/bubbleSort/bubble_sort.cpp b/Sorting/bubbleSort/bubble_sort.cpp new file mode 100644 index 000000000..0f27e42f1 --- /dev/null +++ b/Sorting/bubbleSort/bubble_sort.cpp @@ -0,0 +1,33 @@ +/* Bubble Sort implementation in C++ + * Author : Manvi Gupta + * Input : array length and elements + * Output : Sorted array elements + */ +#include +using namespace std; + +int n; + +void bubble_Sort(int a[]) + { + + for(int i=0; i a[j+1]) + { + swap(a[j+1], a[j]); + } + } + + int main() + { + cin >> n; + int a[n]; + for(int i=0; i> a[i]; + bubble_Sort(a); + for (int i = 0; i < n; i++) { + std::cout << a[i] << '\n'; + } + return 0; + }