Here you can find the source of swap(T[] a, int i1, int i2)
Parameter | Description |
---|---|
T | Type that implements Comparable |
a | Array of objects that implement comparable |
i1 | index of object to be switched |
i2 | second index of object to be switched |
private static <T extends Comparable> void swap(T[] a, int i1, int i2)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w.j a v a 2 s . c o m * Swaps objects at specified index in array * * @param <T> Type that implements Comparable * @param a Array of objects that implement comparable * @param i1 index of object to be switched * @param i2 second index of object to be switched */ private static <T extends Comparable> void swap(T[] a, int i1, int i2) { T temp = a[i1]; a[i1] = a[i2]; a[i2] = temp; } }