MERGSORT - Mergesort

no tags 

Simple. Sort the numbers on the standard input using the merge sort algorithm. Don't try to cheat by just calling your build in functions... I can see your source.

Input

On the standard input you will receive N (1 <= N <= 100000). Each number will fit in 32-bit integer

Output

Output the same integers in a sorted manner. Smallest to largest.

Example

Input:
7 3 2 5 4 3

Output:
2 3 3 4 5 7

hide comments
Andi: 2013-11-18 04:48:07

Nevermind, how u said, u get it in the string.

Last edit: 2013-11-18 05:07:08
Ouditchya Sinha: 2013-04-25 12:28:06

@bansal, use
i = 0 ;
while( scanf("%d",&n) != EOF ) { a[i++] = n ; }

Breno: 2012-09-04 19:46:58

you have to receive the numbers into a string

bansal: 2012-08-28 20:30:17

how will i know how many numbers are there ?????

Felipe Lima [UFS]: 2012-06-04 23:48:52

Anurag, the input is finished with end of file

Anurag Atri: 2011-03-14 03:19:06

how will i know how many numbers are there ?Or how can i know the end of input .

যোবায়ের: 2009-09-23 17:23:27

Number of inversions can also be counted by quicksort, but a bit tedious.
A problem can be mentioned at UVA OJ, 10810, ULTRA QUICK SORT

David Pìgøímek (Davpe): 2009-03-08 18:49:33

I think, this problem is really good, finally something, that forces me to program MergeSort ;). But it should be in tutorial, so no one could bother cheating.

.:: Pratik ::.: 2009-11-03 13:49:41

why is SPOJ going down these days?

Brian Bi: 2009-03-02 21:35:19

How about counting the number of inversions in the sequence? It's doable with mergesort but not any other sort (I think), and is an intrinsic property of the sequence, whereas the left/right switch count seems a bit... ad hoc. For example, given the sequence 3 1 2, the number of switches depends on whether you split it as 3 | 1 2 or 3 1 | 2.

Last edit: 2009-03-02 21:35:19

Added by:Nikola P Borisov
Date:2008-11-17
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET