#K58022. Custom Bubble Sort Implementation
Custom Bubble Sort Implementation
Custom Bubble Sort Implementation
You are given an array of integers. Your task is to sort the array in ascending order by implementing the Bubble Sort algorithm without using any built-in sorting functions.
The Bubble Sort algorithm works by repeatedly swapping adjacent elements if they are in the wrong order. Its time complexity is $$O(n^2)$$ in the worst-case scenario.
Important: Read input from stdin
and write the sorted array to stdout
. The sorted numbers should be output on a single line separated by a single space.
inputFormat
The input is given from stdin
and consists of two lines:
- The first line contains a single integer n representing the number of elements in the array.
- The second line contains n space-separated integers.
outputFormat
Output the sorted array on one line. The numbers must be space-separated. Write the output to stdout
.
6
34 7 23 32 5 62
5 7 23 32 34 62