#C8457. Sort a Singly Linked List

    ID: 52441 Type: Default 1000ms 256MiB

Sort a Singly Linked List

Sort a Singly Linked List

Given a singly linked list, your task is to sort it in ascending order. The objective is to rearrange the nodes such that their values are in increasing order, i.e. \(a_1 \le a_2 \le \cdots \le a_n\). You need to read the linked list from the input, sort it, and output the sorted list.

Example:
Input:
5 2 3 1 5 4
Output:
1 2 3 4 5

inputFormat

The input is given from stdin and has the following format:

  1. The first line contains a single integer \(n\) denoting the number of nodes in the linked list.
  2. The second line contains \(n\) integers separated by spaces, representing the values of the nodes.

outputFormat

Print the sorted linked list as a sequence of integers separated by spaces to stdout.

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