怎么编这个程序..A file contains a large quantity N of numbers (say around 1000000).Design an algorithm to extract the n largest numbers from the file (say n is around 1000).There is room in memory to hold an array a[1]...a[n] of n numbers,but

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/20 05:03:47
怎么编这个程序..A file contains a large quantity N of numbers (say around 1000000).Design an algorithm to extract the n largest numbers from the file (say n is around 1000).There is room in memory to hold an array a[1]...a[n] of n numbers,but
xN@_eVS$z詪TE9,aILݰ,B)I _m/ⴕHJHxy!>u4j{=ڏη%/k1 sfB3E"\)cs\k lR"f!5?Cjyb )Xpˎ 9PmgD܊boǍ'* &Z\5R&5 dX6{#su3b?Gw`Z%0$z_ -w]̱s22j`HXy,Gg܅Yr $,e(sW@I 1\+U6M?ƛ1"-AoGA(l)$jTAggpcJ5qqd 3=OF~7>.WxvD^+<\Uo/wCmn&3![)ୄO2YW/dΥEQ|'^ z[ݚ8nۣTF ȯ+1bqL+p627/.v]|˽Tz_OF|;IyVza/( oxxCw8YsTX$k>k Dؔ

怎么编这个程序..A file contains a large quantity N of numbers (say around 1000000).Design an algorithm to extract the n largest numbers from the file (say n is around 1000).There is room in memory to hold an array a[1]...a[n] of n numbers,but
怎么编这个程序.
.A file contains a large quantity N of numbers (say around 1000000).Design an algorithm to extract the n largest numbers from the file (say n is around 1000).There is room in memory to hold an array a[1]...a[n] of n numbers,but there is not room to hold the whole file.The algorithm should scan the file sequentially just once.(You have to come and show me your program.)
我想用JAVA编.请各位提供下思路

怎么编这个程序..A file contains a large quantity N of numbers (say around 1000000).Design an algorithm to extract the n largest numbers from the file (say n is around 1000).There is room in memory to hold an array a[1]...a[n] of n numbers,but
不难编.
但是我不会用java
一个一个读进去 读第一个数的时候 就把这个数存到array的第一个位置
a[0] 然后把它设为max 然后后面的数 输进去 和已经存在array里面的数比较 如果它比max大 那它就是max 然后array里的其他数往后面移 a[n]=a[n+1] 如果它比某一个大 而那个数是a[k] 那现在它就是a[k] a[k]以后的所有数 都往后移 这样就可以了