Class Bogosort

java.lang.Object
algorithmcomparison.Bogosort

public class Bogosort extends Object
Bogosort
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int[]
    bogosort(int[] arr)
    Sorts the array using Bogosort
    static boolean
    isSorted(int[] a)
    Checks if the array is sorted
    static void
    shuffle(int[] a)
    Shuffles the array
    static void
    swap(int[] a, int i, int j)
    Swaps two array elements

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Bogosort

      public Bogosort()
  • Method Details

    • bogosort

      public static int[] bogosort(int[] arr)
      Sorts the array using Bogosort
      Parameters:
      arr - The unsorted dataset
      Returns:
      sorted The sorted dataset
    • shuffle

      public static void shuffle(int[] a)
      Shuffles the array
      Parameters:
      a - The unsorted array
    • swap

      public static void swap(int[] a, int i, int j)
      Swaps two array elements
      Parameters:
      a - The array that is being sorted
      i - The index of the element that is swapped
      j - The index of the element that is swapped
    • isSorted

      public static boolean isSorted(int[] a)
      Checks if the array is sorted
      Parameters:
      a - The unsorted or sorted array
      Returns:
      true or false