#C14066. Bubble Sort Implementation
Bubble Sort Implementation
Bubble Sort Implementation
You are required to implement the Bubble Sort algorithm to sort a list of integers in non-decreasing order. The Bubble Sort algorithm works by repeatedly stepping through the list, comparing adjacent elements, and swapping them if they are in the wrong order. This process is repeated until no more swaps are needed, which means the list is sorted. The number of comparisons in the worst-case scenario can be expressed by the formula: ( \frac{n(n-1)}{2} ), where ( n ) is the number of elements in the list.
inputFormat
The input consists of two lines. The first line contains an integer ( n ), the number of elements in the list. The second line contains ( n ) space-separated integers.
outputFormat
Output the sorted list in non-decreasing order on one line, with each number separated by a single space.## sample
7
34 2 23 67 4 18 19
2 4 18 19 23 34 67