Java Bubble Sort bubbleSorting(double array[], double[] diagramsUsed)

Here you can find the source of bubbleSorting(double array[], double[] diagramsUsed)

Description

Taken from http://www.java2novice.com/java-sorting-algorithms/bubble-sort/

License

Open Source License

Parameter

Parameter Description
array that will be sorted
diagramsUsed the number associated to the diagram

Return

sorted array and diagrams used by minimizing array

Declaration

public static double[][] bubbleSorting(double array[], double[] diagramsUsed) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w w  w  . j ava2  s  . c  o  m
     * Taken from
     * http://www.java2novice.com/java-sorting-algorithms/bubble-sort/
     * 
     * @param array
     *            that will be sorted
     * @param diagramsUsed
     *            the number associated to the diagram
     * @return sorted array and diagrams used by minimizing array
     */
    public static double[][] bubbleSorting(double array[], double[] diagramsUsed) {
        int n = array.length;
        int k;
        for (int m = n; m >= 0; m--) {
            for (int i = 0; i < n - 1; i++) {
                k = i + 1;
                if (array[i] > array[k]) {
                    swapNumbers(i, k, array);
                    swapNumbers(i, k, diagramsUsed);
                }
            }

        }
        double[][] arrayAndPositions = { array, diagramsUsed };
        return arrayAndPositions;
    }

    /**
     * 
     * @param i
     *            row index
     * @param j
     *            col index
     * @param array
     *            modified vector
     */
    private static void swapNumbers(int i, int j, double[] array) {
        double temp;
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}

Related

  1. bubbleSort(int[] array)
  2. BubbleSort(int[] data)
  3. bubbleSort(int[] source)
  4. bubbleSort(String[] p_array)
  5. bubbleSortArray(String[] str)
  6. bubblesortList(String[][] SortList)