From 672f9dc57f66495d9784c71fd55d51ac75505902 Mon Sep 17 00:00:00 2001 From: William Grigor Date: Fri, 21 Dec 2018 23:01:52 -0600 Subject: [PATCH] Bubble Sort now uses vectors --- Sorting/Bubble Sort.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Sorting/Bubble Sort.cpp b/Sorting/Bubble Sort.cpp index c94a45efc..01c421314 100644 --- a/Sorting/Bubble Sort.cpp +++ b/Sorting/Bubble Sort.cpp @@ -1,19 +1,22 @@ //Bubble Sort #include +#include using namespace std; int main() { int n; + cout << "Enter the amount of numbers to sort: "; cin >> n; - int Array[n]; - cout<<"\nEnter any 6 Numbers for Unsorted Array : "; - + vector numbers; + cout << "Enter " << n << " numbers: "; + int num; //Input for(int i=0; i>Array[i]; + cin >> num; + numbers.push_back(num); } //Bubble Sorting @@ -21,19 +24,23 @@ int main() { for(int j=0; jArray[j+1]) + if(numbers[j]>numbers[j+1]) { - int temp=Array[j]; - Array[j]=Array[j+1]; - Array[j+1]=temp; + swap(numbers[j], numbers[j+1]); } } } //Output cout<<"\nSorted Array : "; - for(int i=0; i