Hallo zusammen, ich habe diese Aufgabe. Wie kann ich die durschnittliche Laufzeit in Millisekunden ermitteln?
Mein Code, den ich geschrieben habe aber weiß nicht was noch fehlt :
Java:
Mein Code:
import java.util.*;
public class SortierVergleich
{
public static void randomPermutation(int[] a)
{
//einen neuen Zufallszahlengenerator anlegen
Random gen = new Random();
for(int i = a.length-1; i > 0; i--)
{
//Element fuer Position i zufaellig waehlen
int p = gen.nextInt(i+1);
//Elemente an Positionen p und i tauschen
int h = a;
a = a[p];
a[p] = h;
}
}
public static void fillArray(int[] a)
{
for(int i = 0; i < a.length; i++){a = i;}
}
public static void main(String[] args)
{
int[] folge = new int[Integer.parseInt(args[0])];
fillArray(folge);
long start = System.currentTimeMillis();
randomPermutation(folge);
BubbleSort.performBubbleSortOn(folge);
long ende = System.currentTimeMillis();
long dauer = ende - start;
System.out.println("Das Permutieren hat " + dauer + " Millisekunden gedauert");
}
}
-----------------------------------------------------------------------------------------------------------------
BubbleSort Code :
class BubbleSort
{
static void performBubbleSortOn(int[] f)
{
boolean getauscht = true;
while(getauscht)
{
getauscht = false;
//Testen, ob irgendwo noch etwas getauscht
//werden muss
for(int i = f.length-1; i > 0; i--)
{
if(f < f[i-1])
{
int h = f;
f = f[i-1];
f[i-1] = h;
getauscht = true;
}
}
}
}
static void printArray(int[] a)
{
for(int i = 0; i < a.length; i++)
{
System.out.print(a + " ");
}
System.out.print("\n");
}
public static void main(String[] args)
{
int[] folge = {13,4,15,3,16,12,2,1,51,26,11};
printArray(folge);
performBubbleSortOn(folge);
printArray(folge);
}
}
Ich wäre seehr dankbar, wenn jemand mir helfen würde....
Vielen Dank im Voraus!
Zuletzt bearbeitet: