Here you can find the source of swap(T[] arr, int pos1, int pos2)
Parameter | Description |
---|---|
arr | the array containing the elements to swap |
pos1 | the position of the first element |
pos2 | the position of the second element |
public static <T extends Comparable<T>> void swap(T[] arr, int pos1, int pos2)
//package com.java2s; //License from project: Open Source License public class Main { /**/*w w w. j a v a 2 s . c o m*/ * Exchanges two elements in the array. * @param arr the array containing the elements to swap * @param pos1 the position of the first element * @param pos2 the position of the second element */ public static <T extends Comparable<T>> void swap(T[] arr, int pos1, int pos2) { final T temp = arr[pos1]; arr[pos1] = arr[pos2]; arr[pos2] = temp; } }