#C13519. Bubble Sort

    ID: 43066 Type: Default 1000ms 256MiB

Bubble Sort

Bubble Sort

You are given a list of integers. Your task is to implement the Bubble Sort algorithm to sort this list in ascending order.

The Bubble Sort algorithm repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. This process is repeated until no more swaps are needed, indicating that the list is sorted. Formally, for an array \(A = [a_1, a_2, \dots, a_n]\), the algorithm performs the following procedure:

\[ \text{for } i = 0 \text{ to } n-1:\] \[ \quad \text{for } j = 0 \text{ to } n-i-2:\] \[ \quad\quad \text{if } a_j > a_{j+1} \text{ then swap } a_j \text{ and } a_{j+1} \]

Once the procedure completes, the array will be sorted in ascending order.

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated integers.

outputFormat

Output the sorted list in ascending order as space-separated integers on a single line.

## sample
5
1 2 3 4 5
1 2 3 4 5