From 7d4b253690ba15c0782e237a7e021e6c46f35e23 Mon Sep 17 00:00:00 2001
From: jwansek <eddie.atten.ea29@gmail.com>
Date: Fri, 5 Mar 2021 15:49:57 +0000
Subject: added linked list

---
 SortingAlgos.java | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

(limited to 'SortingAlgos.java')

diff --git a/SortingAlgos.java b/SortingAlgos.java
index eecb3fa..980bc48 100644
--- a/SortingAlgos.java
+++ b/SortingAlgos.java
@@ -1,3 +1,5 @@
+import java.lang.reflect.Array;
+import java.lang.Class;
 
 public class SortingAlgos {
 
@@ -109,6 +111,43 @@ public class SortingAlgos {
         return A;
     }
 
+    /* ************************************************************* */
+    // Name:        Merge Sort
+    // Basis:       Comparison
+    // Complexity:   - O(nlogn) in all cases
+    // Space:       O(n) memory usage (cannot sort in place)
+    // Stability:   Stable
+    // Informal Description:
+    //          Merge sort is a recursive algorithm. It works under
+    //          the principal that an array with 1 item in it is sorted.
+    //          In the divide stage, the array is split up into many 
+    //          arrays with single items using recursion. Then in the
+    //          conquer stage, elements are recursively merged together
+    //          linearlly.
+    //              Base Case:
+    //                  A single element, return it
+    //              Divide Stage:
+    //                  Split the array into two halves, left and right
+    //                  Recursively call mergeSort on these halves
+    //              Conquer Stage:
+    //                  Combine the two sorted arrays into one sorted
+    //                  array, using the merge() algorithm
+    // Notes:
+    //          Invented by von Neumann in 1945.
+    //          The operation is O(nlogn) which is pretty much as good
+    //          as you can get for general-purpose sorting algorithms.
+    //          It has the same complexity in every case, since it
+    //          fiddles with elements even if they're already sorted.
+    //          Consequently insertionSort will be faster if lots of the
+    //          elements are already sorted. Timsort merges the two
+    //          algorithms for the best preformance.
+    /* ************************************************************* */
+    public static <T extends Comparable<T>> T[] mergeSort(T[] A) {
+        throw new UnsupportedOperationException("Not supported yet.");
+        // return mergeSortRecurse(A, 0, A.length - 1);
+    }
+
+
     public static <T> void printArray(T[] A) {
         System.out.print("[");
         for (T i : A) {
@@ -119,8 +158,9 @@ public class SortingAlgos {
 
     public static void main(String[] args) {
         Integer myArray[] = {5, 6, 42, 12, 62, 9, 0, 21, 19};
-        printArray(selectionSort(myArray));
-        printArray(bubbleSort(myArray));
-        printArray(insertionSort(myArray));
+        // printArray(selectionSort(myArray));
+        // printArray(bubbleSort(myArray));
+        // printArray(insertionSort(myArray));
+        
     }
 }
\ No newline at end of file
-- 
cgit v1.2.3