Compare commits
No commits in common. "master" and "main" have entirely different histories.
|
|
@ -1,7 +1,5 @@
|
|||
package pr2.algorithmen.sorting;
|
||||
|
||||
import pr2.algorithmen.sort.Sorter;
|
||||
|
||||
public class BubbleSort implements Sorter {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package pr2.algorithmen.sorting;
|
||||
|
||||
import pr2.algorithmen.sort.Sorter;
|
||||
|
||||
public class InsertionSort implements Sorter {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package pr2.algorithmen.sorting;
|
||||
|
||||
import pr2.algorithmen.sort.Sorter;
|
||||
|
||||
public class MergeSort implements Sorter {
|
||||
|
||||
void msort(int[] array, int le, int ri, int[] helper) {
|
||||
int i, j;
|
||||
int i, j, k;
|
||||
if (ri > le) {
|
||||
// zu sortierendes Feld teilen
|
||||
int mid = (ri + le) / 2;
|
||||
|
|
@ -15,17 +13,17 @@ public class MergeSort implements Sorter {
|
|||
msort(array, mid + 1, ri, helper);
|
||||
|
||||
// Hilfsfeld aufbauen
|
||||
for (int k = le; k <= mid; k++) {
|
||||
for (k = le; k <= mid; 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];
|
||||
}
|
||||
|
||||
// Ergebnisse mischen über Hilfsfeld
|
||||
i = le; j = ri;
|
||||
for (int k = le; k <= ri; k++) {
|
||||
for (k = le; k <= ri; k++) {
|
||||
if (helper[i] < helper[j]) {
|
||||
array[k] = helper[i++];
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package pr2.algorithmen.sorting;
|
||||
|
||||
import pr2.algorithmen.sort.Sorter;
|
||||
|
||||
public class QuickSort implements Sorter {
|
||||
|
||||
int partition(int[] array, int u, int o, int p) {
|
||||
|
|
|
|||
|
|
@ -1,23 +1,21 @@
|
|||
package pr2.algorithmen.sorting;
|
||||
|
||||
import pr2.algorithmen.sort.Sorter;
|
||||
|
||||
public class SelectionSort implements Sorter {
|
||||
|
||||
@Override
|
||||
public void sort(int[] data) {
|
||||
int pos = data.length - 1;
|
||||
while (pos >= 0) {
|
||||
int marker = data.length - 1;
|
||||
while (marker >= 0) {
|
||||
// bestimme größtes Element
|
||||
int indexMax = 0;
|
||||
for (int i = 0; i <= pos; i++) {
|
||||
if (data[i] > data[indexMax]) {
|
||||
indexMax = i;
|
||||
int max = 0;
|
||||
for (int i = 1; i <= marker; i++) {
|
||||
if (data[i] > data[max]) {
|
||||
max = i;
|
||||
}
|
||||
}
|
||||
// tausche array[pos] mit diesem Element
|
||||
swap(data, pos, indexMax);
|
||||
pos--;
|
||||
// tausche array[marker] mit diesem Element
|
||||
swap(data, marker, max);
|
||||
marker--;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@ public interface Sorter {
|
|||
void sort(int[] data);
|
||||
|
||||
default void swap(int[] data, int i1, int i2) {
|
||||
if (i1 == i2) {
|
||||
return;
|
||||
}
|
||||
|
||||
int tmp = data[i1];
|
||||
data[i1] = data[i2];
|
||||
data[i2] = tmp;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
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.*;
|
||||
|
||||
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];
|
||||
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");
|
||||
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 is = testAlgorithm(InsertionSort.class, size, runs);
|
||||
long ms = testAlgorithm(MergeSort.class, size, runs);
|
||||
|
|
@ -63,6 +58,7 @@ public class TestSorting {
|
|||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
measure(10, 1000, 100);
|
||||
|
||||
final int size = 1000;
|
||||
|
|
|
|||
|
|
@ -1,47 +1,53 @@
|
|||
package pr2.exceptions.callstack;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @author Thomas Smits
|
||||
*/
|
||||
public class HandleOrDeclare {
|
||||
|
||||
public void openFile(String dateiName)
|
||||
throws IOException, FileNotFoundException {
|
||||
// Datei öffnen
|
||||
}
|
||||
|
||||
public void datenSchreiben(String dateiName, String sqlStatement)
|
||||
throws FileNotFoundException, IOException, SQLException {
|
||||
openFile(dateiName);
|
||||
// Mit Datenbank arbeiten
|
||||
}
|
||||
|
||||
public void dateiAnlegen(String dateiName)
|
||||
throws FileNotFoundException, IOException {
|
||||
try {
|
||||
datenSchreiben(dateiName, "SELECT * FROM x");
|
||||
} catch (SQLException ex) {
|
||||
// Datenbank Problem beheben ;-)
|
||||
}
|
||||
}
|
||||
|
||||
public void userInterface() {
|
||||
String dateiName = askUser();
|
||||
|
||||
try {
|
||||
dateiAnlegen(dateiName);
|
||||
} catch (FileNotFoundException ex) {
|
||||
// Benutzer:in erneut nach namen Fragen
|
||||
} catch (IOException ex) {
|
||||
// Benutzer:in auf Problem hinweisen
|
||||
}
|
||||
}
|
||||
|
||||
public String askUser() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
package pr2.exceptions.callstack;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @author Thomas Smits
|
||||
*/
|
||||
public class HandleOrDeclare {
|
||||
|
||||
public void openFile(String dateiName)
|
||||
throws IOException, FileNotFoundException {
|
||||
// Datei öffnen
|
||||
}
|
||||
|
||||
public void datenSchreiben(String dateiName, String sqlStatement)
|
||||
throws FileNotFoundException, IOException, SQLException {
|
||||
|
||||
openFile(dateiName);
|
||||
// Mit Datenbank arbeiten
|
||||
}
|
||||
|
||||
public void dateiAnlegen(String dateiName)
|
||||
throws FileNotFoundException, IOException {
|
||||
|
||||
try {
|
||||
datenSchreiben(dateiName, "SELECT * FROM x");
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
// Datenbank Problem beheben ;-)
|
||||
}
|
||||
}
|
||||
|
||||
public void userInterface() {
|
||||
String dateiName = askUser();
|
||||
|
||||
try {
|
||||
dateiAnlegen(dateiName);
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
// Benutzer erneut nach namen Fragen
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// Benutzer auf Problem hinweisen
|
||||
}
|
||||
}
|
||||
|
||||
public String askUser() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
*/
|
||||
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 org.junit.jupiter.api.Assertions;
|
||||
|
||||
public class BrokenTest {
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
public void testKaputt() {
|
||||
String s1 = new String("Hallo");
|
||||
assertEquals("Hallo", s1);
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue