Update Bubble Sort.cpp

Removed unnecessary usage of break and restored the single entry and single exit mechanism
This commit is contained in:
PRITI1999 2019-09-17 21:49:29 +05:30 committed by GitHub
parent 641514acb4
commit c05fe43168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ using namespace std;
int main()
{
int n;
short swap_check = 0;
short swap_check = 1;
cout << "Enter the amount of numbers to sort: ";
cin >> n;
vector<int> numbers;
@ -22,7 +22,7 @@ int main()
}
//Bubble Sorting
for (int i = 0; i < n; i++)
for (int i = 0; (i < n) && (swap_check == 1); i++)
{
swap_check = 0;
for (int j = 0; j < n - 1 - i; j++)
@ -33,10 +33,6 @@ int main()
swap(numbers[j], numbers[j + 1]);
}
}
if (swap_check == 0)
{
break;
}
}
//Output