Bubble Sort
Easyjavapythonccppjavascript
Sort an integer array in ascending order using the Bubble Sort technique — repeatedly compare neighbouring elements and swap them when they are in the wrong order. The judge checks the final sorted output.
Input Format
The first line contains an integer N. The second line contains N space-separated integers.
Output Format
Print the N integers in ascending order, separated by single spaces, on one line.
Example 1
Input
4 5 1 4 2
Output
1 2 4 5
Explanation: Neighbouring elements are compared and swapped until the array is sorted.
- 1 <= N <= 100000
- -1000000000 <= A[i] <= 1000000000
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Linear SearchEasy · java, python, c, cpp, javascriptSolve Problem
- Binary SearchEasy · java, python, c, cpp, javascriptSolve Problem
- First Occurrence in Sorted ArrayEasy · java, python, c, cpp, javascriptSolve Problem