Bubble Sort

 #include <iostream>

using namespace std;


#include "solution.h"

void bubbleSort(int *input, int size)

{

    //Write your code here

    int start=0;

    int end=size-1;

    for(int j=1;j<size-1;j++){

        for(int i=0;i<(size-j);i++){

            if(input[i+1]<input[i]){

                int temp=input[i];

                input[i]=input[i+1];

                input[i+1]=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;

}

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings