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