Compare commits
No commits in common. "master" and "main" have entirely different histories.
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,53 @@
|
||||||
package pr2.exceptions.callstack;
|
|
||||||
|
package pr2.exceptions.callstack;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.FileNotFoundException;
|
||||||
import java.sql.SQLException;
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
/**
|
|
||||||
* @author Thomas Smits
|
/**
|
||||||
*/
|
* @author Thomas Smits
|
||||||
public class HandleOrDeclare {
|
*/
|
||||||
|
public class HandleOrDeclare {
|
||||||
public void openFile(String dateiName)
|
|
||||||
throws IOException, FileNotFoundException {
|
public void openFile(String dateiName)
|
||||||
// Datei öffnen
|
throws IOException, FileNotFoundException {
|
||||||
}
|
// Datei öffnen
|
||||||
|
}
|
||||||
public void datenSchreiben(String dateiName, String sqlStatement)
|
|
||||||
throws FileNotFoundException, IOException, SQLException {
|
public void datenSchreiben(String dateiName, String sqlStatement)
|
||||||
openFile(dateiName);
|
throws FileNotFoundException, IOException, SQLException {
|
||||||
// Mit Datenbank arbeiten
|
|
||||||
}
|
openFile(dateiName);
|
||||||
|
// Mit Datenbank arbeiten
|
||||||
public void dateiAnlegen(String dateiName)
|
}
|
||||||
throws FileNotFoundException, IOException {
|
|
||||||
try {
|
public void dateiAnlegen(String dateiName)
|
||||||
datenSchreiben(dateiName, "SELECT * FROM x");
|
throws FileNotFoundException, IOException {
|
||||||
} catch (SQLException ex) {
|
|
||||||
// Datenbank Problem beheben ;-)
|
try {
|
||||||
}
|
datenSchreiben(dateiName, "SELECT * FROM x");
|
||||||
}
|
}
|
||||||
|
catch (SQLException ex) {
|
||||||
public void userInterface() {
|
// Datenbank Problem beheben ;-)
|
||||||
String dateiName = askUser();
|
}
|
||||||
|
}
|
||||||
try {
|
|
||||||
dateiAnlegen(dateiName);
|
public void userInterface() {
|
||||||
} catch (FileNotFoundException ex) {
|
String dateiName = askUser();
|
||||||
// Benutzer:in erneut nach namen Fragen
|
|
||||||
} catch (IOException ex) {
|
try {
|
||||||
// Benutzer:in auf Problem hinweisen
|
dateiAnlegen(dateiName);
|
||||||
}
|
}
|
||||||
}
|
catch (FileNotFoundException ex) {
|
||||||
|
// Benutzer erneut nach namen Fragen
|
||||||
public String askUser() {
|
}
|
||||||
return null;
|
catch (IOException ex) {
|
||||||
}
|
// Benutzer auf Problem hinweisen
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String askUser() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
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