swap will swap the elements in heap at index and index2 - Java Collection Framework

Java examples for Collection Framework:Heap

Description

swap will swap the elements in heap at index and index2

Demo Code


//package com.java2s;

public class Main {
    /**//from  w ww  .j  a  v  a2 s . c  o  m
     * 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;
    }
}

Related Tutorials