mirror of
https://github.com/tu-darmstadt-informatik/AuD_TU_Darmstadt.git
synced 2025-12-13 01:35:51 +00:00
Uebung 2 H1 complette
This commit is contained in:
parent
68987e0fb2
commit
2bfa4265b6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,7 +3,9 @@ package lab;
|
||||
/**
|
||||
* Aufgabe H1b)
|
||||
*
|
||||
* Abgabe von: <name>, <name> und <name>
|
||||
* Abgabe von: Jian Dong jd81vuti
|
||||
* Zezhi Chen zc75diqa
|
||||
* Hanyu Sun hs54keri
|
||||
*/
|
||||
|
||||
public class Card {
|
||||
@ -43,8 +45,7 @@ public class Card {
|
||||
* @param other The object we compare this to.
|
||||
* @return -1, 0 or 1
|
||||
*/
|
||||
public int compareTo(Card other) { //by dj, ganz richtig! :)
|
||||
// TODO: implement
|
||||
public int compareTo(Card other) {
|
||||
if (this.value > other.value) {
|
||||
return 1;
|
||||
}
|
||||
@ -82,7 +83,7 @@ public class Card {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {//this.suit.ordinal() == 1
|
||||
else {
|
||||
if (other.suit.ordinal() == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -6,7 +6,9 @@ import java.util.Random;
|
||||
/**
|
||||
* Aufgabe H1b)
|
||||
*
|
||||
* Abgabe von: <name>, <name> und <name>
|
||||
* Abgabe von: Jian Dong jd81vuti
|
||||
* Zezhi Chen zc75diqa
|
||||
* Hanyu Sun hs54keri
|
||||
*/
|
||||
|
||||
import frame.SortArray;
|
||||
@ -22,13 +24,12 @@ public class HybridSort {
|
||||
*/
|
||||
public void sort(SortArray array, int k) {
|
||||
assert(k>=0);
|
||||
// TODO: Implement dj
|
||||
int p = 0;
|
||||
int r = array.getNumberOfItems() - 1;
|
||||
hySort(array, k, p, r);
|
||||
}
|
||||
|
||||
public void hySort(SortArray array,int k, int p, int r) { //dj
|
||||
public void hySort(SortArray array,int k, int p, int r) {
|
||||
int q = 0;
|
||||
if (r > p) {
|
||||
if ( r - p +1 >= k) {
|
||||
@ -42,7 +43,7 @@ public class HybridSort {
|
||||
}
|
||||
}
|
||||
|
||||
public int partion(SortArray array, int p, int r) { //dj
|
||||
public int partion(SortArray array, int p, int r) {
|
||||
int pivot = randomPivot(p, r);
|
||||
cardSwap(array, p, pivot);
|
||||
Card x = new Card(array.getElementAt(p)); // Pivotelement
|
||||
@ -56,20 +57,6 @@ public class HybridSort {
|
||||
cardSwap(array, i, p);
|
||||
return i;
|
||||
|
||||
/*
|
||||
int pivot = randomPivot(p, r);
|
||||
cardSwap(array, r, pivot);
|
||||
Card x = new Card(array.getElementAt(r)); // Pivotelement
|
||||
int i = p-1;
|
||||
for (int j = p ; j < r ; j++) {
|
||||
if (array.getElementAt(j).compareTo(x) <= 0 ) {
|
||||
i = i + 1;
|
||||
cardSwap(array, i, j);
|
||||
}
|
||||
}
|
||||
cardSwap(array, i+1, r);
|
||||
return i+1;
|
||||
*/
|
||||
}
|
||||
|
||||
public int randomPivot(int p, int r) {//gamz richtig $dj$
|
||||
@ -82,7 +69,7 @@ public class HybridSort {
|
||||
array.setElementAt(j, tmp);
|
||||
}
|
||||
|
||||
//below are methods for insertionSort $dj$
|
||||
//below are methods for insertionSort
|
||||
public void insertionSort(SortArray array, int p, int r) {
|
||||
int i;
|
||||
for (int j = p+1; j<= r; j++) {
|
||||
@ -96,7 +83,7 @@ public class HybridSort {
|
||||
}
|
||||
}
|
||||
|
||||
//below are methods for mergeSort $dj$
|
||||
//below are methods for mergeSort
|
||||
/*
|
||||
public void mergeSort(SortArray array, int p, int r) { //dj
|
||||
int q;
|
||||
|
||||
@ -5,16 +5,17 @@ import java.util.Random;
|
||||
/**
|
||||
* Aufgabe H1c)
|
||||
*
|
||||
* Abgabe von: <name>, <name> und <name>
|
||||
* Abgabe von: Jian Dong jd81vuti
|
||||
* Zezhi Chen zc75diqa
|
||||
* Hanyu Sun hs54keri
|
||||
*/
|
||||
|
||||
/**
|
||||
* Use a random pivot within Quick Sort.
|
||||
*/
|
||||
public class HybridSortRandomPivot extends HybridSort {
|
||||
// TODO: Implement
|
||||
|
||||
public int randomPivot(int p, int r) {//gamz richtig $dj$
|
||||
public int randomPivot(int p, int r) {
|
||||
Random rand = new Random();
|
||||
int rp = rand.nextInt((r - p) + 1) + p;
|
||||
return rp;
|
||||
|
||||
@ -3,7 +3,9 @@ package lab;
|
||||
/**
|
||||
* Aufgabe H1
|
||||
*
|
||||
* Abgabe von: <name>, <name> und <name>
|
||||
* Abgabe von: Jian Dong jd81vuti
|
||||
* Zezhi Chen zc75diqa
|
||||
* Hanyu Sun hs54keri
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -14,8 +16,8 @@ import org.junit.jupiter.api.Test;
|
||||
* Use this class to implement your own tests.
|
||||
*/
|
||||
|
||||
import frame.SortArray; //dj
|
||||
import frame.CardTestfileReader; //dj
|
||||
//import frame.SortArray; //
|
||||
//import frame.CardTestfileReader; //
|
||||
|
||||
class YourTests {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user