Here you can find the source of sort3(String[] a, int x, int y, int z)
Parameter | Description |
---|---|
a | represents the array with the strings for sorting. |
x | position of the first string. |
y | position of the second string. |
z | position of the third string. |
private static void sort3(String[] a, int x, int y, int z)
//package com.java2s; /**/*from w w w . j a va2s. co m*/ * Copyright (c) 1997, 2015 by ProSyst Software GmbH and others. * 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 */ public class Main { /** * Auxiliary method for sorting lexicographically the strings at the positions x, y and z. * * @param a represents the array with the strings for sorting. * @param x position of the first string. * @param y position of the second string. * @param z position of the third string. */ private static void sort3(String[] a, int x, int y, int z) { if (a[x].compareTo(a[y]) > 0) { if (a[x].compareTo(a[z]) > 0) { if (a[y].compareTo(a[z]) > 0) { swap(a, x, z); } else { swap3(a, x, y, z); } } else { swap(a, x, y); } } else if (a[x].compareTo(a[z]) > 0) { swap3(a, x, z, y); } else if (a[y].compareTo(a[z]) > 0) { swap(a, y, z); } } /** * Auxiliary method for sorting lexicographically the strings. Shuffling strings on positions x and y, as the string * at the position x, goes to the position y, the string at the position y, goes to the position x. * * @param a represents the array with the strings for sorting. * @param x position of the first string. * @param y position of the second string. */ private static void swap(String[] a, int x, int y) { String t = a[x]; a[x] = a[y]; a[y] = t; } /** * Auxiliary method for sorting lexicographically the strings. Shuffling strings on positions x, y and z, as the * string * at the position x, goes to the position z, the string at the position y, goes to the position x and the string * at the position z, goes to the position y. * * @param a represents the array with the strings for sorting. * @param x position of the first string. * @param y position of the second string. * @param z position of the third string. */ private static void swap3(String[] a, int x, int y, int z) { String t = a[x]; a[x] = a[y]; a[y] = a[z]; a[z] = t; } }