(int index)
| 57 | return temp; |
| 58 | } |
| 59 | private void downheap(int index) { |
| 60 | int min = index; |
| 61 | int left = left(index); |
| 62 | int right = right(index); |
| 63 | |
| 64 | if(left < list.size() && list.get(min).compareTo(list.get(left)) > 0) { |
| 65 | min = left; |
| 66 | } |
| 67 | |
| 68 | if(right < list.size() && list.get(min).compareTo(list.get(right)) > 0) { |
| 69 | min = right; |
| 70 | } |
| 71 | |
| 72 | if(min != index) { |
| 73 | swap(min, index); |
| 74 | downheap(min); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public ArrayList<T> heapSort() throws Exception { |
| 79 | ArrayList<T> data = new ArrayList<>(); |