Difficulty Level: Easy

Submissions: 4218 Accuracy:


Absolute List Sorting (Function Problem)

Given a linked list L of N nodes, sorted in ascending order based on the absolute values of its data. Sort the linked list according to the actual values.
Ex: Input : 1 -> -2 -> -3 -> 4 -> -5 
      Output: -5 -> -3 -> -2 -> 1 -> 4

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains a positive integer N denoting the size of linked list. The second line of each test case contains N space separated integers denoting the values of N nodes.

Corresponding to each test case, the expected output will be space separated values of the sorted linked list.

1 <= T <= 100
0 <   N  <= 30
-100 <= L[i] <= 100


1 -3 -4
0 -2 3 -10

-4  -3  1
-10 -2  0  3

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Rajat Jha, Amit Khandelwal

It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use, generate link and share the link here.