Java Array Swap swap(short x[], int[] y, int a, int b)

Here you can find the source of swap(short x[], int[] y, int a, int b)

Description

Swaps x[a] with x[b].

License

Open Source License

Declaration

private static void swap(short x[], int[] y, int a, int b) 

Method Source Code

//package com.java2s;
/**/*from w w  w. j av  a 2 s .c o  m*/
 * <PRE>
 * Name   : com.solidmatrix.regxmaker.util.shared.SortUtils
 * Project: RegXmaker Library
 * Version: 1.1
 * Tier   : N/A (Function Class)
 * Author : Gennadiy Shafranovich
 * Purpose: To provide custom features when sortings
 * Summary: Provides the ability to sort arrays of primitives 
 *          and return an array of ints in which each subset
 *          of the array contains the original position of the value
 *          that resides in the sorted array. Methods are copied from
 *          java.util.Arrays class and then modified to provide this
 *          functionality.
 *
 * Copyright (C) 2001, 2004 SolidMatrix Technologies, Inc.
 * This file is part of RegXmaker Library.
 *
 * RegXmaker Library is is free software; you can redistribute it and/or modify
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * RegXmaker library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Comments: Full, with javadoc.
 *
 * Modification History
 *
 * 01-23-2001  GS Class created and ready for testing
 *
 * 07-05-2004  YS Added licensing information
 * </PRE>
 */

public class Main {
    /**
     * Swaps x[a] with x[b].
     */
    private static void swap(long x[], int[] y, int a, int b) {
        long t = x[a];
        x[a] = x[b];
        x[b] = t;

        int o = y[a];
        y[a] = y[b];
        y[b] = o;
    }

    /**
     * Swaps x[a] with x[b].
     */
    private static void swap(int x[], int[] y, int a, int b) {
        int t = x[a];
        x[a] = x[b];
        x[b] = t;

        int o = y[a];
        y[a] = y[b];
        y[b] = o;
    }

    /**
     * Swaps x[a] with x[b].
     */
    private static void swap(short x[], int[] y, int a, int b) {
        short t = x[a];
        x[a] = x[b];
        x[b] = t;

        int o = y[a];
        y[a] = y[b];
        y[b] = o;
    }

    /**
     * Swaps x[a] with x[b].
     */
    private static void swap(char x[], int[] y, int a, int b) {
        char t = x[a];
        x[a] = x[b];
        x[b] = t;

        int o = y[a];
        y[a] = y[b];
        y[b] = o;
    }

    /**
     * Swaps x[a] with x[b].
     */
    private static void swap(byte x[], int[] y, int a, int b) {
        byte t = x[a];
        x[a] = x[b];
        x[b] = t;

        int o = y[a];
        y[a] = y[b];
        y[b] = o;
    }

    /**
     * Swaps x[a] with x[b].
     */
    private static void swap(double x[], int[] y, int a, int b) {
        double t = x[a];
        x[a] = x[b];
        x[b] = t;

        int o = y[a];
        y[a] = y[b];
        y[b] = o;
    }

    /**
     * Swaps x[a] with x[b].
     */
    private static void swap(float x[], int[] y, int a, int b) {
        float t = x[a];
        x[a] = x[b];
        x[b] = t;

        int o = y[a];
        y[a] = y[b];
        y[b] = o;
    }
}

Related

  1. swap(Object[] arr, int i, int j)
  2. swap(Object[] array)
  3. swap(Object[] array, int a, int b)
  4. swap(Object[] x, int a, int b)
  5. swap(short x[], int a, int b)
  6. swap(short x[], T[] a2, int a, int b)
  7. swap(short[] array, int indexA, int indexB)
  8. swap(String a[], int i, int j)
  9. swap(T[] a, int i1, int i2)