Compare commits

..

No commits in common. "master" and "main" have entirely different histories.
master ... main

1141 changed files with 76 additions and 88 deletions

View File

@ -1,7 +1,5 @@
package pr2.algorithmen.sorting; package pr2.algorithmen.sorting;
import pr2.algorithmen.sort.Sorter;
public class BubbleSort implements Sorter { public class BubbleSort implements Sorter {
@Override @Override

View File

@ -1,7 +1,5 @@
package pr2.algorithmen.sorting; package pr2.algorithmen.sorting;
import pr2.algorithmen.sort.Sorter;
public class InsertionSort implements Sorter { public class InsertionSort implements Sorter {
@Override @Override

View File

@ -1,11 +1,9 @@
package pr2.algorithmen.sorting; package pr2.algorithmen.sorting;
import pr2.algorithmen.sort.Sorter;
public class MergeSort implements Sorter { public class MergeSort implements Sorter {
void msort(int[] array, int le, int ri, int[] helper) { void msort(int[] array, int le, int ri, int[] helper) {
int i, j; int i, j, k;
if (ri > le) { if (ri > le) {
// zu sortierendes Feld teilen // zu sortierendes Feld teilen
int mid = (ri + le) / 2; int mid = (ri + le) / 2;
@ -15,17 +13,17 @@ public class MergeSort implements Sorter {
msort(array, mid + 1, ri, helper); msort(array, mid + 1, ri, helper);
// Hilfsfeld aufbauen // Hilfsfeld aufbauen
for (int k = le; k <= mid; k++) { for (k = le; k <= mid; k++) {
helper[k] = array[k]; helper[k] = array[k];
} }
for (int k = mid; k < ri; k++) { for (k = mid; k < ri; k++) {
helper[ri + mid - k] = array[k + 1]; helper[ri + mid - k] = array[k + 1];
} }
// Ergebnisse mischen über Hilfsfeld // Ergebnisse mischen über Hilfsfeld
i = le; j = ri; i = le; j = ri;
for (int k = le; k <= ri; k++) { for (k = le; k <= ri; k++) {
if (helper[i] < helper[j]) { if (helper[i] < helper[j]) {
array[k] = helper[i++]; array[k] = helper[i++];
} else { } else {

View File

@ -1,7 +1,5 @@
package pr2.algorithmen.sorting; package pr2.algorithmen.sorting;
import pr2.algorithmen.sort.Sorter;
public class QuickSort implements Sorter { public class QuickSort implements Sorter {
int partition(int[] array, int u, int o, int p) { int partition(int[] array, int u, int o, int p) {

View File

@ -1,23 +1,21 @@
package pr2.algorithmen.sorting; package pr2.algorithmen.sorting;
import pr2.algorithmen.sort.Sorter;
public class SelectionSort implements Sorter { public class SelectionSort implements Sorter {
@Override @Override
public void sort(int[] data) { public void sort(int[] data) {
int pos = data.length - 1; int marker = data.length - 1;
while (pos >= 0) { while (marker >= 0) {
// bestimme größtes Element // bestimme größtes Element
int indexMax = 0; int max = 0;
for (int i = 0; i <= pos; i++) { for (int i = 1; i <= marker; i++) {
if (data[i] > data[indexMax]) { if (data[i] > data[max]) {
indexMax = i; max = i;
} }
} }
// tausche array[pos] mit diesem Element // tausche array[marker] mit diesem Element
swap(data, pos, indexMax); swap(data, marker, max);
pos--; marker--;
} }
} }

View File

@ -5,10 +5,6 @@ public interface Sorter {
void sort(int[] data); void sort(int[] data);
default void swap(int[] data, int i1, int i2) { default void swap(int[] data, int i1, int i2) {
if (i1 == i2) {
return;
}
int tmp = data[i1]; int tmp = data[i1];
data[i1] = data[i2]; data[i1] = data[i2];
data[i2] = tmp; data[i2] = tmp;

View File

@ -1,12 +1,5 @@
package pr2.algorithmen.sorting; package pr2.algorithmen.sorting;
import pr2.algorithmen.sort.impl.BubbleSort;
import pr2.algorithmen.sort.impl.InsertionSort;
import pr2.algorithmen.sort.impl.MergeSort;
import pr2.algorithmen.sort.impl.QuickSort;
import pr2.algorithmen.sort.impl.SelectionSort;
import pr2.algorithmen.sort.Sorter;
import java.util.*; import java.util.*;
public class TestSorting { public class TestSorting {
@ -22,9 +15,9 @@ public class TestSorting {
} }
} }
static long testAlgorithm(Class<?> clazz, int size, int runs) { static long testAlgorithm(Class clazz, int size, int runs) {
pr2.algorithmen.sort.Sorter s; Sorter s;
var data = new int[size]; var data = new int[size];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
@ -47,13 +40,15 @@ public class TestSorting {
} }
return System.nanoTime() - start; long runtime = System.nanoTime() - start;
return runtime;
} }
public static void measure(int sizeSteps, int maxSize, int runs) { public static void measure(int size_steps, int max_size, int runs) {
System.out.println("Runs\tBS\tIS\tMS\tQS\tSS"); System.out.println("Runs\tBS\tIS\tMS\tQS\tSS");
for (int size = 0; size <= maxSize; size += sizeSteps) { for (int size = 0; size <= max_size; size += size_steps) {
long bs = testAlgorithm(BubbleSort.class, size, runs); long bs = testAlgorithm(BubbleSort.class, size, runs);
long is = testAlgorithm(InsertionSort.class, size, runs); long is = testAlgorithm(InsertionSort.class, size, runs);
long ms = testAlgorithm(MergeSort.class, size, runs); long ms = testAlgorithm(MergeSort.class, size, runs);
@ -63,6 +58,7 @@ public class TestSorting {
} }
} }
public static void main(String[] args) { public static void main(String[] args) {
measure(10, 1000, 100); measure(10, 1000, 100);
final int size = 1000; final int size = 1000;

View File

@ -1,3 +1,4 @@
package pr2.exceptions.callstack; package pr2.exceptions.callstack;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -16,15 +17,18 @@ public class HandleOrDeclare {
public void datenSchreiben(String dateiName, String sqlStatement) public void datenSchreiben(String dateiName, String sqlStatement)
throws FileNotFoundException, IOException, SQLException { throws FileNotFoundException, IOException, SQLException {
openFile(dateiName); openFile(dateiName);
// Mit Datenbank arbeiten // Mit Datenbank arbeiten
} }
public void dateiAnlegen(String dateiName) public void dateiAnlegen(String dateiName)
throws FileNotFoundException, IOException { throws FileNotFoundException, IOException {
try { try {
datenSchreiben(dateiName, "SELECT * FROM x"); datenSchreiben(dateiName, "SELECT * FROM x");
} catch (SQLException ex) { }
catch (SQLException ex) {
// Datenbank Problem beheben ;-) // Datenbank Problem beheben ;-)
} }
} }
@ -34,10 +38,12 @@ public class HandleOrDeclare {
try { try {
dateiAnlegen(dateiName); dateiAnlegen(dateiName);
} catch (FileNotFoundException ex) { }
// Benutzer:in erneut nach namen Fragen catch (FileNotFoundException ex) {
} catch (IOException ex) { // Benutzer erneut nach namen Fragen
// Benutzer:in auf Problem hinweisen }
catch (IOException ex) {
// Benutzer auf Problem hinweisen
} }
} }

View File

@ -3,13 +3,13 @@
*/ */
package pr2.exceptions.junit; package pr2.exceptions.junit;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
public class BrokenTest { public class BrokenTest {
@Disabled @Test
public void testKaputt() { public void testKaputt() {
String s1 = new String("Hallo"); String s1 = new String("Hallo");
assertEquals("Hallo", s1); assertEquals("Hallo", s1);

Some files were not shown because too many files have changed in this diff Show More