本帖最后由 谢洋 于 2013-3-9 09:52 编辑
1. tr.add(new Student("lili01",23)); 2. tr.add(new Student("lili02",20)); 3. tr.add(new Student("lili03",18)); 4. tr.add(new Student("lili04",30)); 5. tr.add(new Student("lili05",29)); 6. tr.add(new Student("lili06",60)); 7. tr.add(new Student("lili07",24)); 8. tr.add(new Student("lili08",22)); 9. tr.add(new Student("lili09",54)); lili01....compareto.....lili01 lili02....compareto.....lili01 lili03....compareto.....lili01 lili03....compareto.....lili02 lili04....compareto.....lili02 lili04....compareto.....lili01 lili05....compareto.....lili02 lili05....compareto.....lili01 lili05....compareto.....lili04 lili06....compareto.....lili02 lili06....compareto.....lili05 lili06....compareto.....lili04 lili07....compareto.....lili02 lili07....compareto.....lili05 lili07....compareto.....lili01 lili08....compareto.....lili02 lili08....compareto.....lili05 lili08....compareto.....lili01 lili09....compareto.....lili02 lili09....compareto.....lili05 lili09....compareto.....lili04 lili09....compareto.....lili06
从打印的结查与上图来看,注意图的中元素的角标
发现:二权树的比较方式,从集合中已有三个元素开始,每次都是从集合中的2号元素开始比较(其实也是中间);然后再从集合中后面剩下元素的中间处(假设A处)开始比较,如果小于,再从2号到当前(A处)之间的中间(假设B处)那个元开始比;如果大于B处的,那么再从B与A之间的中间(假设C处)开始找,如此下去,直到找到适合的位置
这样子做大大提高了比较的效率 |