Java Array Swap swap(int keys[], int values[], int a, int b)

Here you can find the source of swap(int keys[], int values[], int a, int b)

Description

swap

License

Open Source License

Declaration

private static void swap(int keys[], int values[], int a, int b) 

Method Source Code

//package com.java2s;
/**/*w ww. j  a v  a2s . c  o m*/
 * ****************************************************************************
 * Copyright (c) 2008 SAP AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * SAP AG - initial API and implementation
 * *****************************************************************************
 */

public class Main {
    private static void swap(int keys[], int values[], int a, int b) {
        // swap the keys
        int tmp = keys[a];
        keys[a] = keys[b];
        keys[b] = tmp;

        // swap the values
        tmp = values[a];
        values[a] = values[b];
        values[b] = tmp;
    }

    private static void swap(long keys[], int values[], int a, int b) {
        // swap the keys
        long tmpKey = keys[a];
        keys[a] = keys[b];
        keys[b] = tmpKey;

        // swap the values
        int tmpValue = values[a];
        values[a] = values[b];
        values[b] = tmpValue;
    }
}

Related

  1. swap(int arr[], int i, int j)
  2. swap(int array[], int first, int last)
  3. swap(int arrs[], int i, int j)
  4. swap(int i, int j, Integer[] unsorted)
  5. swap(int i, int j, String[] index)
  6. swap(int[] a, int first, int second)
  7. swap(int[] a, int i, int j)
  8. swap(int[] arr, int a, int b)
  9. swap(int[] arr, int a, int b)