Bubble Sort
Bubble Sort is one of the sorting algorithms that works by repeatedly swapping the adjacent elements of the array if they are not in sorted order.
You are given an unsorted array consisting of N non-negative integers. Your task is to sort the array in non-decreasing order using the Bubble Sort algorithm.
For Example:
Bubble Sort implementation for the given array: {6,2,8,4,10} is shown below :-
Input Format:
The first line of input contains an integer 'T' representing the number of test cases.
Then the test case follows.
The first line of each test case contains integer N denoting the size of the array.
The second line of each test case contains 'N' space-separated integers representing the array elements
Output Format:
The only line of output of each test case should print the sorted array in increasing order.
Output for each test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function. Also, you need to update the given array in place only.
Constraints:
1 <= T <= 100
1 <= N <= 100
1 <= Arr[i] <= 1000
Where 'T' represents the number of test cases, 'N' represents the size of the array, and Arr[i] represents the elements of the array.
Time Limit: 1 sec.
CodingNinjas
author
2y
1. created array
2. sorted using bubble sort
3. optimized
CodingNinjas
author
2y
Implementation
Bubble sort is a standard sorting algorithm that uses nested loops to check all adjacent elements in an array and swap them if they are not in the right order of sorting.
Steps :
- Use a f...read more
Vaibhav Mali
2y
created array
2. sorted using bubble sort
3. optimized
Rathod Vinod
2y
1. created array
2. sorted using bubble sort
3. optimized
Add answer anonymously...
Top Wipro Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app