Don't even ask...
In theory, I'm trying to create the most inefficient sorting algorithm of all time.
Why? I'm bored and don't feel like doing my comp sci homework where we're supposed to use the MOST efficient sorting algorithm we can find.
Anyway, here's my code. I know it's really messy right now and can be made into much less lines of code and such, but I wrote this pretty late at night, so I'll just update it whenever I get the chance. Also pushing to github whenever I get it set up on this computer, lol.
What it does RIGHT NOW:
Right now, it only checks the first number, but this is how it works:
Compare the first number to the second number. Are they equal? If so, compare the first number to the third number. If they aren't, randomize the entire array and start over.
Questions? Comments? Suggestions? Criticism? All are welcome.Code:import java.util.*;
class EfficientSort
{
public static void main(String[] args)
{
//Print title and stuff
System.out.println("This is EfficientSort, made by 323.");
//Initialize Random Num Gen
Random rgen = new Random();
//Initialize array
int[] numbers = new int[11];
//Populate array with 0-10
for (int i=0; i<numbers.length; i++)
{
numbers[i] = i;
}
//Print original array before randomization
System.out.println("Original array:");
for (int z=0; z<numbers.length; z++)
{
System.out.print(numbers[z] + ", ");
}
//Start new line for next row of numbers
System.out.println("");
//Randomize array
for (int x=0; x<numbers.length; x++)
{
int randomPosition = rgen.nextInt(numbers.length);
int temp = numbers[x];
numbers[x] = numbers[randomPosition];
numbers[randomPosition] = temp;
}
//Print array after randomization
System.out.println("Randomized Array:");
for (int y=0; y<numbers.length; y++)
{
System.out.print(numbers[y] + ", ");
}
//Print starting message
System.out.println("");
System.out.println("Beginning sorting algorithm...");
//Check if the numbers are in the right order
int r = 0;
int num = 1;
while (r == 0) //r only = 1 when entire set is sorted
{
while (num<numbers.length)
{
if (numbers[0] < numbers[num])
{
num++;
}
else
{
//Randomize array
for (int x=0; x<numbers.length; x++)
{
int randomPosition = rgen.nextInt(numbers.length);
int temp = numbers[x];
numbers[x] = numbers[randomPosition];
numbers[randomPosition] = temp;
}
for (int z=0; z<numbers.length; z++)
{
System.out.print(numbers[z] + ", ");
}
System.out.println("");
}
}
System.out.println("");
System.out.println("Sorted First Number!");
System.out.println("First Number Sorted Array");
for (int z=0; z<numbers.length; z++)
{
System.out.print(numbers[z] + ", ");
}
r = 1;
}
}
}