From 4a9b834dc7985fe36bd8855013ef3fc373db46bb Mon Sep 17 00:00:00 2001 From: Ash <121093841+Ashirz@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:13:04 +0000 Subject: [PATCH] Update SortingAlgorithms1.java Organised the main method --- src/Algorithms/SortingAlgorithms1.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Algorithms/SortingAlgorithms1.java b/src/Algorithms/SortingAlgorithms1.java index cfe6f4a..c8cc4ab 100644 --- a/src/Algorithms/SortingAlgorithms1.java +++ b/src/Algorithms/SortingAlgorithms1.java @@ -5,20 +5,16 @@ public class SortingAlgorithms1 { public static void main(String[] args) { int array[] = { 5, 8, 9, 1, 2, 6, 4 }; - sort(array, 0, array.length - 1); + sort(array, 0, array.length - 1); + System.out.println("After Quick Sort:"); + printArray(array); - System.out.println("Implementing Quick sort"); - for (int i : array) - System.out.print(i); - System.out.println(); - - divide(array); - - System.out.println("Implementing Merge sort"); - for (int i : array) - System.out.print(i); - System.out.println(); + // Reset the array for subsequent sorts + array = new int[] { 5, 8, 9, 1, 2, 6, 4 }; + mergeSort(array); + System.out.println("After Merge Sort:"); + printArray(array); } // Merge sort methods divide & conquer