怎么编这个程序..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/05/06 21:54:17
怎么编这个程序..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
怎么编这个程序.
.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]以后的所有数 都往后移 这样就可以了