GitLab der Philipps-Universität Marburg

Skip to content
Snippets Groups Projects
Commit 834f58e7 authored by jannikseus's avatar jannikseus
Browse files

remove unnecessary code

parent 57530491
No related branches found
Tags ue01_v01
No related merge requests found
Pipeline #2961 failed
......@@ -86,58 +86,6 @@ public class ColaImpl implements COLAInsert<Integer, String> {
return mergedArray;
}
public static ColaElement[] merge_sort(ColaElement[] unsortedArray)
{
if (unsortedArray.length > 1) {
int mid = unsortedArray.length / 2;
ColaElement[] left = new ColaElement[mid];
for (int i = 0; i <= mid - 1; i++){
left[i] = unsortedArray[i];
}
ColaElement[] right = new ColaElement[unsortedArray.length - mid];
for (int i = mid; i <= unsortedArray.length - 1; i++) {
right[i - mid] = unsortedArray[i];
}
left = merge_sort(left);
right = merge_sort(right);
return verschmelze(left, right);
}
else
{
return unsortedArray;
}
}
private static ColaElement[] verschmelze(ColaElement[] left, ColaElement[] right)
{
ColaElement[] newLeft = new ColaElement[left.length + right.length];
int indexLeft = 0;
int indexRight = 0;
int indexRes = 0;
while (indexLeft < left.length && indexRight < right.length) {
if (left[indexLeft].compareTo(right[indexRight]) < 0) {
newLeft[indexRes] = left[indexLeft];
indexLeft += 1;
} else {
newLeft[indexRes] = right[indexRight];
indexRight += 1;
}
indexRes += 1;
}
while (indexLeft < left.length) {
newLeft[indexRes] = left[indexLeft];
indexLeft += 1;
indexRes += 1;
}
while (indexRight < right.length) {
newLeft[indexRes] = right[indexRight];
indexRight += 1;
indexRes += 1;
}
return newLeft;
}
public static void main(String[] args) {
COLAInsert<Integer, String> colaInsert = new ColaImpl();
colaInsert.insertElement(1, "a");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment