Skip to content

Commit 2d13aed

Browse files
authored
Create Bubble Sort (Iterative) Linked List
1 parent fc4c0a0 commit 2d13aed

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Given a singly linked list of integers, sort it using 'Bubble Sort.' Note : No need to print the list, it has already been taken care. Only return the new head to the list.
3+
4+
Input format :
5+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
6+
The first and the only line of each test case or query contains the elements of the singly linked list separated by a single space.
7+
Remember/Consider :
8+
While specifying the list elements for input, -1 indicates the end of the singly linked list and hence, would never be a list element
9+
10+
Output format :
11+
For each test case/query, print the elements of the sorted singly linked list.
12+
Output for every test case will be printed in a seperate line.
13+
14+
Constraints :
15+
1 <= t <= 10^2
16+
0 <= M <= 10^5
17+
Where M is the size of the singly linked list.
18+
Time Limit: 1sec
19+
20+
Sample Input 1 :
21+
1
22+
10 9 8 7 6 5 4 3 -1
23+
Sample Output 1 :
24+
3 4 5 6 7 8 9 10
25+
26+
Sample Input 2 :
27+
2
28+
-1
29+
10 -5 9 90 5 67 1 89 -1
30+
Sample Output 2 :
31+
-5 1 5 9 10 67 89 90
32+
*/

0 commit comments

Comments
 (0)