Skip to content

Commit

Permalink
Update SortingAlgorithms1.java
Browse files Browse the repository at this point in the history
Re organised the code
  • Loading branch information
Ashirz authored Dec 18, 2024
1 parent 4a9b834 commit 452b062
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Algorithms/SortingAlgorithms1.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ 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);

// Reset the array for subsequent sorts
array = new int[] { 5, 8, 9, 1, 2, 6, 4 };

mergeSort(array);
divide(array);
System.out.println("After Merge Sort:");
printArray(array);

}

// Helper method to print the array
public static void printArray(int[] arr) {
for (int i : arr) {
System.out.print(i + " ");
}
System.out.println();
}

// Merge sort methods divide & conquer
public static void divide(int[] array) {
Expand Down Expand Up @@ -46,7 +55,9 @@ public static void divide(int[] array) {
}

divide(LeftArray);

divide(RightArray);

conquer(LeftArray, RightArray, array);

}
Expand Down

0 comments on commit 452b062

Please sign in to comment.