0005_Fifth push edited[directories], added[Trees]

This commit is contained in:
Meruemon
2022-07-02 20:40:21 +02:00
parent 6ecc372964
commit 07409bf7a1
13 changed files with 178 additions and 49 deletions

View File

@@ -1,25 +0,0 @@
public class Main {
public static void main(String[] args) {
//Test BubbleSortInSitu
MyPair[] arrPairs = {new MyPair(2,2), new MyPair(0,0), new MyPair(1,1), new MyPair(3,3)};
sort_algorithms.myBubbleSortInSitu(arrPairs);
System.out.println(arrPairs[0].toString() + arrPairs[1].toString() + arrPairs[2].toString() + arrPairs[3].toString());
//Test BubbleSortNotInSitu
MyPair[] arrPairs2 = {new MyPair(2,2), new MyPair(0,0), new MyPair(1,1), new MyPair(3,3)};
MyPair[] arrPairs3 = sort_algorithms.myBubbleSortNotInSitu(arrPairs2);
System.out.println(arrPairs3[0].toString() + arrPairs3[1].toString() + arrPairs3[2].toString() + arrPairs3[3].toString());
System.out.println(arrPairs2[0].toString() + arrPairs2[1].toString() + arrPairs2[2].toString() + arrPairs2[3].toString());
//Test SelectionSortInSitu
MyPair[] arrPairs4 = {new MyPair(2,2), new MyPair(0,0), new MyPair(1,1), new MyPair(3,3)};
sort_algorithms.mySelectionSortInSitu(arrPairs4);
System.out.println(arrPairs4[0].toString() + arrPairs4[1].toString() + arrPairs4[2].toString() + arrPairs4[3].toString());
//
//sort_algorithms.myQuickSortInSitu(arrPairs2);
//System.out.println(arrPairs2[0].toString() + arrPairs2[1].toString() + arrPairs2[2].toString() + arrPairs2[3].toString());
}
}

View File

@@ -1,3 +1,4 @@
package MyList;
public class MyList {
public MyListElement first;
private int size = 0;

View File

@@ -1,3 +1,4 @@
package MyList;
public class MyListElement {
public MyPair data;
public MyListElement next;

View File

@@ -1,3 +1,4 @@
package MyList;
public class MyPair {
public Object key;
public Object data;

View File

@@ -1,5 +1,10 @@
package MySearch;
import java.util.List;
import MyList.MyList;
import MyList.MyListElement;
import MyList.MyPair;
public class search_algorithms {
//Data doesnt have to be sorted.

View File

@@ -1,3 +1,6 @@
package MySort;
import MyList.MyPair;
public class sort_algorithms {
/**
@@ -168,6 +171,6 @@ public class sort_algorithms {
}
private static void myHeapsortInSitu(MyPair[] arr) {
}
}

View File

@@ -1,23 +0,0 @@
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MyTest {
@Test
public void testSequentailSearch() {
MyList list = new MyList();
list.add(new MyPair(1,3));
list.add(new MyPair(2,4));
assertEquals(3, search_algorithms.sequentielSearchList(1, list).data);
assertEquals(4, search_algorithms.sequentielSearchList(2, list).data);
}
@Test
public void testBinarySearch() {
MyPair[] pairs = {new MyPair(1,3), new MyPair(2,4)};
assertEquals(3, search_algorithms.binarySearch(1, pairs).data);
assertEquals(4, search_algorithms.binarySearch(2, pairs).data);
}
}

77
MyTest/MyTest.java Normal file
View File

@@ -0,0 +1,77 @@
package MyTest;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import MyList.MyList;
import MyList.MyPair;
import MySearch.search_algorithms;
import MySort.sort_algorithms;
public class MyTest {
@Test
public void testSequentialSearch() {
MyList list = new MyList();
list.add(new MyPair(1,3));
list.add(new MyPair(2,4));
assertEquals(3, search_algorithms.sequentielSearchList(1, list).data);
assertEquals(4, search_algorithms.sequentielSearchList(2, list).data);
}
@Test
public void testBinarySearch() {
MyPair[] pairs = {new MyPair(1,3), new MyPair(2,4)};
assertEquals(3, search_algorithms.binarySearch(1, pairs).data);
assertEquals(4, search_algorithms.binarySearch(2, pairs).data);
}
@Test
public void testExponentialSearch() {
MyPair[] pairs = {new MyPair(1,3), new MyPair(2,4)};
assertEquals(3, search_algorithms.exponentialSearch(1, pairs).data);
assertEquals(4, search_algorithms.exponentialSearch(2, pairs).data);
}
@Test
public void testBubbleSortInSitu() {
//Test BubbleSortInSitu
MyPair[] arrPairs0 = {new MyPair(2,2), new MyPair(0,0), new MyPair(1,1), new MyPair(3,3)};
sort_algorithms.myBubbleSortInSitu(arrPairs0);
for (int i = 0; i < arrPairs0.length; i++) {
assertEquals(i, arrPairs0[i].getKeyAsInt());
}
}
@Test
public void testBubbleSortNotInSitu() {
//Test BubbleSortNotInSitu
MyPair[] arrPairs0 = {new MyPair(2,2), new MyPair(0,0), new MyPair(1,1), new MyPair(3,3)};
MyPair[] arrPairs1 = sort_algorithms.myBubbleSortNotInSitu(arrPairs0);
for (int i = 0; i < arrPairs1.length; i++) {
assertEquals(i, arrPairs1[i].getKeyAsInt());
}
}
@Test
public void testSelectionSortInSitu() {
//Test SelectionSortInSitu
MyPair[] arrPairs0 = {new MyPair(2,2), new MyPair(0,0), new MyPair(1,1), new MyPair(3,3)};
sort_algorithms.mySelectionSortInSitu(arrPairs0);
for (int i = 0; i < arrPairs0.length; i++) {
assertEquals(i, arrPairs0[i].getKeyAsInt());
}
}
@Test
public void testSelectionSortNotInSitu() {
//Test SelectionSortNotInSitu
MyPair[] arrPairs0 = {new MyPair(2,2), new MyPair(0,0), new MyPair(1,1), new MyPair(3,3)};
MyPair[] arrPairs1 = sort_algorithms.mySelectionSortNotInSitu(arrPairs0);
for (int i = 0; i < arrPairs0.length; i++) {
assertEquals(i, arrPairs1[i].getKeyAsInt());
}
}
}

14
MyTrees/MyBinaryTree.java Normal file
View File

@@ -0,0 +1,14 @@
package MyTrees;
public class MyBinaryTree {
public MyTreeNode root;
private int size;
public MyBinaryTree() {
root = null;
}
public int getSize() {
return this.size;
}
}

View File

@@ -0,0 +1,12 @@
package MyTrees;
public class MyMaxHeapTree extends MyBinaryTree {
public MyMaxHeapTree() {
super();
}
public MyTreeNode[] asArray() {
MyTreeNode[] treeAsArray = new MyTreeNode[this.getSize()];
return treeAsArray;
}
}

View File

@@ -0,0 +1,5 @@
package MyTrees;
public class MyMinHeapTree {
}

View File

@@ -0,0 +1,5 @@
package MyTrees;
public class MyRedBlackTree extends MyBinaryTree {
}

53
MyTrees/MyTreeNode.java Normal file
View File

@@ -0,0 +1,53 @@
package MyTrees;
public class MyTreeNode {
private MyTreeNode leftChild;
private MyTreeNode rightChild;
private Object key;
private Object data;
public MyTreeNode() {
this.leftChild = null;
this.rightChild = null;
this.key = null;
this.data = null;
}
//David Setter Methods
public void setLeftChild(MyTreeNode leftNode) {
this.leftChild = leftNode;
}
public void setRightChild(MyTreeNode rightNode) {
this.rightChild = rightNode;
}
public void setKey(Object key) {
this.key = key;
}
public void setData(Object data) {
this.data = data;
}
//David Getter Methods
public MyTreeNode getLeftChild() {
return this.leftChild;
}
public MyTreeNode getRightChild() {
return this.rightChild;
}
public Object getKey() {
return this.key;
}
public Object getData() {
return this.data;
}
public int getKeyAsInt() {
return (int)this.key;
}
}