Compare commits
No commits in common. "main" and "Arbeit" have entirely different histories.
11
.project
11
.project
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>PR2-Hummel-3024753</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
/bin/
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
|
|
||||||
public class Knoten {
|
|
||||||
|
|
||||||
private int wert;
|
|
||||||
private Knoten nachfolger;
|
|
||||||
|
|
||||||
Knoten(int wert){
|
|
||||||
this.wert = wert;
|
|
||||||
this.nachfolger=null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void einfuegenAmEnde(int wert) {
|
|
||||||
if(this.nachfolger == null) {
|
|
||||||
Knoten k = new Knoten(wert);
|
|
||||||
this.nachfolger=k;
|
|
||||||
}else {
|
|
||||||
nachfolger.einfuegenAmEnde(wert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int auslesenAnPos(int pos) throws Exception {
|
|
||||||
|
|
||||||
int r = 0;
|
|
||||||
// sind wir bereits an der Pos angekommen?
|
|
||||||
if(pos == 0) {
|
|
||||||
r= this.wert;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(pos >0 && nachfolger !=null) {
|
|
||||||
// nein! zähler verringern und an Nachfolger weitergeben
|
|
||||||
pos--;
|
|
||||||
// haben wir noch Nachfolger an die wir es weitergeben können?
|
|
||||||
|
|
||||||
if(nachfolger==null) {
|
|
||||||
|
|
||||||
throw new IndexOutOfBoundsException("Illegal Statement");
|
|
||||||
}else {
|
|
||||||
nachfolger.auslesenAnPos(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void loeschenAnPos(int pos) throws Exception{
|
|
||||||
if(this.nachfolger==null) {
|
|
||||||
throw new IndexOutOfBoundsException();
|
|
||||||
}
|
|
||||||
if(pos>1) {
|
|
||||||
this.nachfolger = nachfolger.nachfolger;
|
|
||||||
}else {
|
|
||||||
pos --;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWert() {return this.wert;}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// End of Class
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
|
|
||||||
public class LinkedList {
|
|
||||||
private Knoten kopf;
|
|
||||||
|
|
||||||
LinkedList(int wert){
|
|
||||||
kopf = new Knoten(wert);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void einfuegenAmEnde(int wert) {
|
|
||||||
kopf.einfuegenAmEnde(wert);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int auslesenAnPos(int pos) throws Exception {
|
|
||||||
|
|
||||||
return kopf.auslesenAnPos(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loeschenAnPos(int pos) throws Exception {
|
|
||||||
kopf.loeschenAnPos(pos);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.function.ThrowingRunnable;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class LinkedListTest {
|
|
||||||
|
|
||||||
private static final ThrowingRunnable IndexOutOfBoundsException = null;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void test() throws Exception {
|
|
||||||
LinkedList L = new LinkedList(11);
|
|
||||||
L.einfuegenAmEnde(10);
|
|
||||||
L.einfuegenAmEnde(9);
|
|
||||||
L.einfuegenAmEnde(8);
|
|
||||||
L.einfuegenAmEnde(7);
|
|
||||||
|
|
||||||
Assert.assertNotSame(3, L.auslesenAnPos(3));
|
|
||||||
Assert.assertNotSame(3, L.auslesenAnPos(5));
|
|
||||||
Assert.assertNotSame(3, L.auslesenAnPos(7));
|
|
||||||
Assert.assertNotSame(4, L.auslesenAnPos(6));
|
|
||||||
|
|
||||||
|
|
||||||
LinkedList R = new LinkedList(10);
|
|
||||||
R.einfuegenAmEnde(3);
|
|
||||||
R.einfuegenAmEnde(4);
|
|
||||||
R.einfuegenAmEnde(5);
|
|
||||||
R.einfuegenAmEnde(6);
|
|
||||||
R.einfuegenAmEnde(7);
|
|
||||||
|
|
||||||
Assert.assertNotSame(3, R.auslesenAnPos(0));
|
|
||||||
Assert.assertNotSame(3, R.auslesenAnPos(2));
|
|
||||||
Assert.assertNotSame(3, R.auslesenAnPos(5));
|
|
||||||
Assert.assertNotSame(4, R.auslesenAnPos(2));
|
|
||||||
|
|
||||||
Assert.assertEquals(10, R.auslesenAnPos(0));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
import java.util.LinkedList;
|
|
||||||
public class RadixSort {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int[] arr = {10,9,8,7,6,5,4,3,2,1};
|
|
||||||
radixSort(arr);
|
|
||||||
for(int i : arr) System.out.println(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//int Arr
|
|
||||||
public static int[] radixSort(int[] arr) {
|
|
||||||
int größteZ=arr[0];
|
|
||||||
|
|
||||||
//Buckets als Listen anlegen
|
|
||||||
LinkedList<Integer> B0 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B1 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B2 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B3 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B4 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B5 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B6 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B7 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B8 = new LinkedList<>();
|
|
||||||
LinkedList<Integer> B9 = new LinkedList<>();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(int i = 0; i < arr.length; i++) {
|
|
||||||
if(arr[i] > größteZ) größteZ=arr[i];
|
|
||||||
}
|
|
||||||
int cnt=1;
|
|
||||||
while(größteZ / 10 >0) {
|
|
||||||
größteZ= größteZ%10;
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(int i = 0; i< cnt; i++) {
|
|
||||||
//Befuellen der Buckets;
|
|
||||||
for(int d = 0; d< arr.length; d++ ) {
|
|
||||||
int r = arr[i] % 10;
|
|
||||||
switch(r) {
|
|
||||||
case 0: B0.add(arr[i]);
|
|
||||||
case 1: B1.add(arr[i]);
|
|
||||||
case 2: B2.add(arr[i]);
|
|
||||||
case 3: B3.add(arr[i]);
|
|
||||||
case 4: B4.add(arr[i]);
|
|
||||||
case 5: B5.add(arr[i]);
|
|
||||||
case 6: B6.add(arr[i]);
|
|
||||||
case 7: B7.add(arr[i]);
|
|
||||||
case 8: B8.add(arr[i]);
|
|
||||||
case 9: B9.add(arr[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Buckets durchlaufen und wieder einsortierten in die ursprüngliche Arr
|
|
||||||
int e =0;
|
|
||||||
for(int in : B0) {arr[e]= in; e++;}
|
|
||||||
for(int in : B1) {arr[e]= in; e++;}
|
|
||||||
for(int in : B2) {arr[e]= in; e++;}
|
|
||||||
for(int in : B3) {arr[e]= in; e++;}
|
|
||||||
for(int in : B4) {arr[e]= in; e++;}
|
|
||||||
for(int in : B5) {arr[e]= in; e++;}
|
|
||||||
for(int in : B6) {arr[e]= in; e++;}
|
|
||||||
for(int in : B7) {arr[e]= in; e++;}
|
|
||||||
for(int in : B8) {arr[e]= in; e++;}
|
|
||||||
for(int in : B9) {arr[e]= in; e++;}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class RadixSortTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void test() {
|
|
||||||
int[] sort = {9,8,7,6,5,4,3,2,1,0};
|
|
||||||
int[] sortS = {0,1,2,3,4,5,6,7,8,9};
|
|
||||||
|
|
||||||
int[] sort2 = {9,27,10,8,7,6,5,4,3,2,1,0};
|
|
||||||
int[] sortS2 = {0,1,2,3,4,5,6,7,8,9,10,27};
|
|
||||||
|
|
||||||
Assert.assertEquals(sortS, RadixSort.radixSort(sort));
|
|
||||||
Assert.assertEquals(sortS2, RadixSort.radixSort(sort2));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue