mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Update Bubble Sort.cpp
Removed unnecessary usage of break and restored the single entry and single exit mechanism
This commit is contained in:
parent
641514acb4
commit
c05fe43168
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user