diff --git a/code bubble sort.cpp b/code bubble sort.cpp new file mode 100644 index 00000000..daaf4f8b --- /dev/null +++ b/code bubble sort.cpp @@ -0,0 +1,55 @@ +#include +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; + } +} \ No newline at end of file