First copy the no's from file to a local array,coz it reduces time complexity...though space complexity increases.
Then perform a radix sort.. if u want even the worst case complexity to be O(n) else you have many sorting algorithms..
yael
Sep 18th, 2006
create an array of size 2000, and initialize its cells to 0.
then, for every number i in the file array[i+1] = 1;
after going over the file, just go over the array and print i for each array[i+1] that has 1.
manik sheeri
Nov 7th, 2006
the problem can be solved using one array of size 2000.copy all the numbers to the array at once and then use the following int array[2001];int tmp;for(int i=1;i<=2000;i++){tmp=array[i];array[i]=array[tmp];array[tmp]=tmp;}
There are no's between 1 to 2000 in a file line by line.print the no's in sorted order in o(n) complexity