diff --git a/Sorting/Bubble Sort.cpp b/Sorting/Bubble Sort.cpp index 01c421314..fed01bfc5 100644 --- a/Sorting/Bubble Sort.cpp +++ b/Sorting/Bubble Sort.cpp @@ -7,12 +7,14 @@ using namespace std; int main() { int n; - cout << "Enter the amount of numbers to sort: "; + short swap_check=0; + cout << "Enter the amount of numbers to sort: "; cin >> n; vector numbers; cout << "Enter " << n << " numbers: "; int num; - //Input + + //Input for(int i=0; i> num; @@ -22,13 +24,19 @@ int main() //Bubble Sorting for(int i=0; inumbers[j+1]) { + swap_check=1; swap(numbers[j], numbers[j+1]); } } + if(swap_check == 0) + { + break; + } } //Output @@ -43,4 +51,5 @@ int main() cout << numbers[i] << endl; } } + return 0; } diff --git a/Sorting/Insertion Sort.cpp b/Sorting/Insertion Sort.cpp index f449ecb77..af66550ec 100644 --- a/Sorting/Insertion Sort.cpp +++ b/Sorting/Insertion Sort.cpp @@ -9,7 +9,7 @@ int main() cout<<"\nEnter the length of your array : "; cin>>n; int Array[n]; - cout<<"\nEnter the Numbers for Unsorted Array : "; + cout<<"\nEnter any "<