Tabelle fertig
parent
c172fb9890
commit
5543fc1f16
|
|
@ -1,10 +1,15 @@
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SortAlgo {
|
public class SortAlgo {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(SortAlgo.class.getName());
|
||||||
|
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
|
|
||||||
int[] bubble = {6,5,4,3,2,1};
|
int[] bubble = {6,5,4,3,2,1};
|
||||||
int[] select = {6,5,4,3,2,1};
|
int[] select = {6,5,4,3,2,1};
|
||||||
int[] insert = {3,6,1,5,2,4};
|
int[] insert = {6,5,4,3,2,1};
|
||||||
|
|
||||||
int[] erg1 = bubblesort(bubble);
|
int[] erg1 = bubblesort(bubble);
|
||||||
for (int i = 0; i < erg1.length;i++)
|
for (int i = 0; i < erg1.length;i++)
|
||||||
|
|
@ -24,6 +29,7 @@ public class SortAlgo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] bubblesort (int[] arr) {
|
public static int[] bubblesort (int[] arr) {
|
||||||
|
int d = 0;
|
||||||
int temp = -1;
|
int temp = -1;
|
||||||
for (int i = 0; i < arr.length - 1;i++) {
|
for (int i = 0; i < arr.length - 1;i++) {
|
||||||
for (int a = 0; a < arr.length -1 ;a++) {
|
for (int a = 0; a < arr.length -1 ;a++) {
|
||||||
|
|
@ -31,29 +37,36 @@ public class SortAlgo {
|
||||||
temp = arr[a+1];
|
temp = arr[a+1];
|
||||||
arr[a+1] = arr[a];
|
arr[a+1] = arr[a];
|
||||||
arr[a] = temp;
|
arr[a] = temp;
|
||||||
|
d++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("Anzahl der Durchläufe: " + d);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] selectionsort (int[] arr) {
|
public static int[] selectionsort (int[] arr) {
|
||||||
|
int d = 0;
|
||||||
int temp = -1;
|
int temp = -1;
|
||||||
for (int i = 0; i < arr.length - 1;i++) {
|
for (int i = 0; i < arr.length - 1;i++) {
|
||||||
int min = i;
|
int min = i;
|
||||||
for(int a = i; a < arr.length ;a++) {
|
for(int a = i; a < arr.length ;a++) {
|
||||||
if(arr[a] < arr[min]) {
|
if(arr[a] < arr[min]) {
|
||||||
min = a;
|
min = a;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
temp = arr[i];
|
temp = arr[i];
|
||||||
arr[i] = arr[min];
|
arr[i] = arr[min];
|
||||||
arr[min] = temp;
|
arr[min] = temp;
|
||||||
|
d++;
|
||||||
}
|
}
|
||||||
|
log.info("Anzahl der Durchläufe: " + d);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] insertionsort (int[] arr) {
|
public static int[] insertionsort (int[] arr) {
|
||||||
|
int d = 0;
|
||||||
for (int i = 0; i < arr.length - 1 ;i++) {
|
for (int i = 0; i < arr.length - 1 ;i++) {
|
||||||
if (arr[i+1] < arr[i]) {
|
if (arr[i+1] < arr[i]) {
|
||||||
int m = arr[i+1];
|
int m = arr[i+1];
|
||||||
|
|
@ -63,8 +76,10 @@ public class SortAlgo {
|
||||||
j--;
|
j--;
|
||||||
}
|
}
|
||||||
arr[j+1] = m;
|
arr[j+1] = m;
|
||||||
|
d++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("Anzahl der Durchläufe: " + d);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,205 @@
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Tabelle {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] a1 = acht();
|
||||||
|
int[] a2 = sechzehn();
|
||||||
|
int[] a3 = zweiunddreizig();
|
||||||
|
int[] a4 = vierundsechzig();
|
||||||
|
int[] a5 = einszweiacht();
|
||||||
|
int[] a6 = zweifünfsechs();
|
||||||
|
int[] a7 = fünfeinszwei();
|
||||||
|
int[] a8 = einK();
|
||||||
|
int[] a9 = zweiK();
|
||||||
|
int[] a10 = fünfK();
|
||||||
|
int[] a11 = zehnK();
|
||||||
|
|
||||||
|
System.out.print("Größe des Arrays ");System.out.print("8 ");System.out.print("16 ");System.out.print("32 ");System.out.print("64 ");System.out.print("128 ");System.out.print("256 ");System.out.print("512 ");System.out.print("1000 ");System.out.print("2000 ");System.out.print("5000 ");System.out.print("10000 ");
|
||||||
|
System.out.println();
|
||||||
|
System.out.print("Bubblesort ");System.out.print(bubblesort(a1)+ " ");System.out.print(bubblesort(a2)+ " ");System.out.print(bubblesort(a3)+ " ");System.out.print(bubblesort(a4)+ " ");System.out.print(bubblesort(a5)+ " ");System.out.print(bubblesort(a6)+ " ");System.out.print(bubblesort(a7)+ " ");System.out.print(bubblesort(a8)+ " ");System.out.print(bubblesort(a9)+ " ");System.out.print(bubblesort(a10)+ " ");System.out.print(bubblesort(a11)+ " ");
|
||||||
|
System.out.println();
|
||||||
|
System.out.print("Selectionsort ");System.out.print(selectionsort(a1)+ " ");System.out.print(selectionsort(a2)+ " ");System.out.print(selectionsort(a3)+ " ");System.out.print(selectionsort(a4)+ " ");System.out.print(selectionsort(a5)+ " ");System.out.print(selectionsort(a6)+ " ");System.out.print(selectionsort(a7)+ " ");System.out.print(selectionsort(a8)+ " ");System.out.print(selectionsort(a9)+ " ");System.out.print(selectionsort(a10)+ " ");System.out.print(selectionsort(a11)+ " ");
|
||||||
|
System.out.println();
|
||||||
|
System.out.print("Insertionsort ");System.out.print(insertionsort(a1)+ " ");System.out.print(insertionsort(a2)+ " ");System.out.print(insertionsort(a3)+ " ");System.out.print(insertionsort(a4)+ " ");System.out.print(insertionsort(a5)+ " ");System.out.print(insertionsort(a6)+ " ");System.out.print(insertionsort(a7)+ " ");System.out.print(insertionsort(a8)+ " ");System.out.print(insertionsort(a9)+ " ");System.out.print(insertionsort(a10)+ " ");System.out.print(insertionsort(a11)+ " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// bestCase worstCase
|
||||||
|
//Bubblesort O(n^2) O(n^2)
|
||||||
|
//Selectionsort O(n) O(n^2)
|
||||||
|
//Insertionsort O(n) O(n^2)
|
||||||
|
|
||||||
|
public static int bubblesort (int[] arr) {
|
||||||
|
int d = 0;
|
||||||
|
int temp = -1;
|
||||||
|
for (int i = 0; i < arr.length - 1;i++) {
|
||||||
|
for (int a = 0; a < arr.length -1 ;a++) {
|
||||||
|
if (arr[a] > arr[a+1]) {
|
||||||
|
temp = arr[a+1];
|
||||||
|
arr[a+1] = arr[a];
|
||||||
|
arr[a] = temp;
|
||||||
|
d++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int selectionsort (int[] arr) {
|
||||||
|
int d = 0;
|
||||||
|
int temp = -1;
|
||||||
|
for (int i = 0; i < arr.length - 1;i++) {
|
||||||
|
int min = i;
|
||||||
|
for(int a = i; a < arr.length ;a++) {
|
||||||
|
if(arr[a] < arr[min]) {
|
||||||
|
min = a;
|
||||||
|
|
||||||
|
}
|
||||||
|
d++;
|
||||||
|
}
|
||||||
|
temp = arr[i];
|
||||||
|
arr[i] = arr[min];
|
||||||
|
arr[min] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int insertionsort (int[] arr) {
|
||||||
|
int d = 0;
|
||||||
|
for (int i = 0; i < arr.length - 1 ;i++) {
|
||||||
|
if (arr[i+1] < arr[i]) {
|
||||||
|
int m = arr[i+1];
|
||||||
|
int j = i;
|
||||||
|
while (j >= 0 && arr[j] > m) {
|
||||||
|
arr[j+1] = arr[j];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
arr[j+1] = m;
|
||||||
|
}
|
||||||
|
d++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] acht () {
|
||||||
|
int[] arr = new int[8];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 8; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] sechzehn () {
|
||||||
|
int[] arr = new int[16];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 16; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int[] zweiunddreizig () {
|
||||||
|
int[] arr = new int[32];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 32; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int[] vierundsechzig () {
|
||||||
|
int[] arr = new int[64];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 64; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int[] einszweiacht () {
|
||||||
|
int[] arr = new int[128];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 128; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int[] zweifünfsechs () {
|
||||||
|
int[] arr = new int[256];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 256; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int[] fünfeinszwei () {
|
||||||
|
int[] arr = new int[512];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 512; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int[] einK () {
|
||||||
|
int[] arr = new int[1000];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 1000; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] zweiK () {
|
||||||
|
int[] arr = new int[2000];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 2000; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] fünfK () {
|
||||||
|
int[] arr = new int[5000];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 5000; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] zehnK () {
|
||||||
|
int[] arr = new int[10000];
|
||||||
|
int i = 0;
|
||||||
|
for (int z = 10000; z > 0; z--) {
|
||||||
|
arr[i] = z;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue