swap将在index和index2处交换堆中的元素
/*from N o w J a v a . c o m*/ //package com.nowjava; public class Main { /** * swap will swap the elements in heap at index and index2 * * @param heap * is the heap to be switched * @param index * is the first element to be switched * @param index2 * is the second element to be switched */ public static void swap(Comparable[] heap, int index, int index2) { Comparable temp = heap[index]; heap[index] = heap[index2]; heap[index2] = temp; } }