From d60cf35da09a66d99ed5a16242c8f8a65b8b7e6f Mon Sep 17 00:00:00 2001 From: Arjit Arora <42044030+arjitarora26@users.noreply.github.com> Date: Sun, 23 Oct 2022 21:07:17 +0530 Subject: [PATCH] Add bubble sort algorithm for C++ --- bubbleSort.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 bubbleSort.cpp diff --git a/bubbleSort.cpp b/bubbleSort.cpp new file mode 100644 index 0000000..659b714 --- /dev/null +++ b/bubbleSort.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; + +void bubbleSort(vector &a) { + int n = a.size(); + + for(int i=0; i a[j]) { + swap(a[i], a[j]); + } + } + } + +} + +int main() { + + int n; + cin >> n; + + vector a(n); + for(int i=0; i> a[i]; + } + + bubbleSort(a); + + for(int i=0; i