Skip to content

Instantly share code, notes, and snippets.

@Zelakolase
Last active October 18, 2021 09:30
Show Gist options
  • Save Zelakolase/e68a8861e287fbea59836c6ca197640e to your computer and use it in GitHub Desktop.
Save Zelakolase/e68a8861e287fbea59836c6ca197640e to your computer and use it in GitHub Desktop.
A Sorting Method using Randomization
public class main {
public static void main(String[] args) {
int[] a = new int[] {250,93,105,314,7,80,92};
int REPEAT = (int) Math.round(Math.pow(a.length,3.0103821378));
int REAL_LENGTH = a.length - 2;
int i = 0;
while(i < REPEAT) {
int DaNumber = RandomNumber(0,REAL_LENGTH+1);
if(a[DaNumber]>a[DaNumber+1]) {
int tmp = a[DaNumber+1];
a[DaNumber+1] = a[DaNumber];
a[DaNumber] = tmp;
}
print(a);
i++;
}
}
public static int RandomNumber(int min, int max) {
return (int) ((Math.random() * (max - min)) + min);
}
public static void print(int[] h) {
for (int element: h) {
System.out.print(element+",");
}
System.out.println("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment