集册 Java实例教程 swap将在index和index2处交换堆中的元素

swap将在index和index2处交换堆中的元素

欢马劈雪     最近更新时间:2020-01-02 10:19:05

513
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;

    }

}