Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hacktoberfest #677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions code bubble sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>
using namespace std;

// #include "solution.h"

void bubbleSort(int input[], int size)
{
// Write your code here
for (int i = 0; i < size - 1; i++)
{
int min = input[i], minindex = i;
for (int j = i + 1; j < size; j++)
{
if (input[j] < min)
{
min = input[j];
minindex = j;
}
}
// swap case
int temp = input[i];
input[i] = input[minindex];
input[minindex] = temp;
}
}

int main()
{

int t;
cin >> t;

while (t--)
{
int size;
cin >> size;

int *input = new int[size];

for (int i = 0; i < size; ++i)
{
cin >> input[i];
}

bubbleSort(input, size);

for (int i = 0; i < size; ++i)
{
cout << input[i] << " ";
}

delete[] input;
cout << endl;
}
}