文件名称:jinbiaosai
下载
别用迅雷、360浏览器下载。
如迅雷强制弹出,可右键点击选“另存为”。
失败请重下,重下不扣分。
如迅雷强制弹出,可右键点击选“另存为”。
失败请重下,重下不扣分。
介绍说明--下载内容均来自于网络,请自行研究使用
如果要在n个数据中挑选出第一大和第二大的数据(要求输出数据所在位置和值),使用什么方法比较的次数最少?我们可以从体育锦标赛中受到启发。
如图【1.png】所示,8个选手的锦标赛,先两两捉对比拼,淘汰一半。优胜者再两两比拼...直到决出第一名。
第一名输出后,只要对黄色标示的位置重新比赛即可。
下面的代码实现了这个算法(假设数据中没有相同值)。
代码中需要用一个数组来表示图中的树(注意,这是个满二叉树, 不足需要补齐)。它不是存储数据本身,而是存储了数据的下标。 第一个数据输出后,它所在的位置被标识为-1-If you want to pick out the largest and second largest data (requires output data location and value), the number of what method to use to compare data in the least in n? We can be inspired sports tournament. [1.png] As shown, the eight players of the tournament, the first to catch on twenty-two competition, eliminated half. Competition winner ... until then twenty-two decided at first. After the first output, as long as the yellow mark to the position of a re-match. The following code implements this algorithm (assuming the data is not the same value). The code needs to use an array to represent the figure of the tree (note that this is a full binary tree, filled less than required). It is not stored in the data itself, but the index data storage. After the first data output, its location is identified as-1
(系统自动生成,下载前可以参看下载内容)
下载文件列表
TEST5.java