mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-12 06:56:59 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -40,8 +40,7 @@ optimized bubble sort algorithm. It's right down there.
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int n;
|
||||
bool swap_check = true;
|
||||
std::cout << "Enter the amount of numbers to sort: ";
|
||||
@@ -51,20 +50,16 @@ int main()
|
||||
int num;
|
||||
|
||||
// Input
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int i = 0; i < n; i++) {
|
||||
std::cin >> num;
|
||||
numbers.push_back(num);
|
||||
}
|
||||
|
||||
// Bubble Sorting
|
||||
for (int i = 0; (i < n) && (swap_check); i++)
|
||||
{
|
||||
for (int i = 0; (i < n) && (swap_check); i++) {
|
||||
swap_check = false;
|
||||
for (int j = 0; j < n - 1 - i; j++)
|
||||
{
|
||||
if (numbers[j] > numbers[j + 1])
|
||||
{
|
||||
for (int j = 0; j < n - 1 - i; j++) {
|
||||
if (numbers[j] > numbers[j + 1]) {
|
||||
swap_check = true;
|
||||
std::swap(numbers[j],
|
||||
numbers[j + 1]); // by changing swap location.
|
||||
@@ -77,14 +72,10 @@ int main()
|
||||
|
||||
// Output
|
||||
std::cout << "\nSorted Array : ";
|
||||
for (int i = 0; i < numbers.size(); i++)
|
||||
{
|
||||
if (i != numbers.size() - 1)
|
||||
{
|
||||
for (int i = 0; i < numbers.size(); i++) {
|
||||
if (i != numbers.size() - 1) {
|
||||
std::cout << numbers[i] << ", ";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::cout << numbers[i] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user