Skip to content

Commit 452b062

Browse files
authored
Update SortingAlgorithms1.java
Re organised the code
1 parent 4a9b834 commit 452b062

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Algorithms/SortingAlgorithms1.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@ public class SortingAlgorithms1 {
55
public static void main(String[] args) {
66
int array[] = { 5, 8, 9, 1, 2, 6, 4 };
77

8-
sort(array, 0, array.length - 1);
8+
sort(array, 0, array.length - 1);
99
System.out.println("After Quick Sort:");
1010
printArray(array);
1111

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

15-
mergeSort(array);
15+
divide(array);
1616
System.out.println("After Merge Sort:");
1717
printArray(array);
18+
1819
}
20+
21+
// Helper method to print the array
22+
public static void printArray(int[] arr) {
23+
for (int i : arr) {
24+
System.out.print(i + " ");
25+
}
26+
System.out.println();
27+
}
1928

2029
// Merge sort methods divide & conquer
2130
public static void divide(int[] array) {
@@ -46,7 +55,9 @@ public static void divide(int[] array) {
4655
}
4756

4857
divide(LeftArray);
58+
4959
divide(RightArray);
60+
5061
conquer(LeftArray, RightArray, array);
5162

5263
}

0 commit comments

Comments
 (0)