mirror of https://github.com/evanferrao/dsa
clean unused code
This commit is contained in:
parent
21cb88226b
commit
42bce32bf4
|
|
@ -35,54 +35,7 @@ public class MergeSort{
|
||||||
merge(arr, beginning, mid, end);
|
merge(arr, beginning, mid, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// static void merge(int arr[], int beginning, int mid, int end){
|
|
||||||
// // find the size of two subarrays to be merged
|
|
||||||
// int n1 = mid - beginning + 1;
|
|
||||||
// int n2 = end - mid;
|
|
||||||
|
|
||||||
// // create temp arrays
|
|
||||||
// int L[] = new int[n1];
|
|
||||||
// int R[] = new int[n2];
|
|
||||||
|
|
||||||
// // copy data to temp arrays
|
|
||||||
// for(int i = 0; i < n1; i++){
|
|
||||||
// L[i] = arr[beginning + i];
|
|
||||||
// }
|
|
||||||
// for(int j = 0; j < n2; j++){
|
|
||||||
// R[j] = arr[mid + 1 + j];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // merge the temp arrays
|
|
||||||
// // initial indexes of first and second subarrays
|
|
||||||
// int i = 0, j = 0;
|
|
||||||
|
|
||||||
// // initial index of merged subarray array
|
|
||||||
// int k = beginning;
|
|
||||||
// while(i < n1 && j < n2){
|
|
||||||
// if(L[i] <= R[j]){
|
|
||||||
// arr[k] = L[i];
|
|
||||||
// i++;
|
|
||||||
// }else{
|
|
||||||
// arr[k] = R[j];
|
|
||||||
// j++;
|
|
||||||
// }
|
|
||||||
// k++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // copy remaining elements of L[] if any
|
|
||||||
// while(i < n1){
|
|
||||||
// arr[k] = L[i];
|
|
||||||
// i++;
|
|
||||||
// k++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // copy remaining elements of R[] if any
|
|
||||||
// while(j < n2){
|
|
||||||
// arr[k] = R[j];
|
|
||||||
// j++;
|
|
||||||
// k++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
static void merge(int[] arr, int low, int mid, int high) {
|
static void merge(int[] arr, int low, int mid, int high) {
|
||||||
ArrayList<Integer> temp = new ArrayList<>(); // temporary array
|
ArrayList<Integer> temp = new ArrayList<>(); // temporary array
|
||||||
int left = low; // starting index of left half of arr
|
int left = low; // starting index of left half of arr
|
||||||
|
|
|
||||||
|
|
@ -57,74 +57,6 @@ public class VisualMergeSort {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to merge two sorted subarrays with level parameter
|
|
||||||
// public static void merge(int[] array, int left, int mid, int right, int currentLevel) {
|
|
||||||
// System.out.printf("%sMerging subarrays from index %d to %d and %d to %d with level %d%s\n", UNDERLINE, left, mid, mid + 1, right, currentLevel, RESET);
|
|
||||||
// System.out.printf("Subarrays before merge: ");
|
|
||||||
// printArray(array, left, mid);
|
|
||||||
// System.out.printf("and ");
|
|
||||||
// printArray(array, mid + 1, right);
|
|
||||||
// System.out.println();
|
|
||||||
|
|
||||||
// // Sizes of the two subarrays to merge
|
|
||||||
// int n1 = mid - left + 1;
|
|
||||||
// int n2 = right - mid;
|
|
||||||
|
|
||||||
// // Create temporary arrays
|
|
||||||
// int[] leftArray = new int[n1];
|
|
||||||
// int[] rightArray = new int[n2];
|
|
||||||
|
|
||||||
// // Copy data to temporary arrays
|
|
||||||
// for (int i = 0; i < n1; i++) {
|
|
||||||
// leftArray[i] = array[left + i];
|
|
||||||
// }
|
|
||||||
// for (int j = 0; j < n2; j++) {
|
|
||||||
// rightArray[j] = array[mid + 1 + j];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Display temporary arrays
|
|
||||||
// System.out.printf("Left array: ");
|
|
||||||
// printArray(leftArray);
|
|
||||||
// System.out.printf("Right array: ");
|
|
||||||
// printArray(rightArray);
|
|
||||||
|
|
||||||
// // Merge the temporary arrays back into the original array
|
|
||||||
// int i = 0, j = 0;
|
|
||||||
// int k = left;
|
|
||||||
// while (i < n1 && j < n2) {
|
|
||||||
// if (leftArray[i] <= rightArray[j]) {
|
|
||||||
// array[k] = leftArray[i];
|
|
||||||
// i++;
|
|
||||||
// } else {
|
|
||||||
// array[k] = rightArray[j];
|
|
||||||
// j++;
|
|
||||||
// }
|
|
||||||
// System.out.printf("Placing %d at index %d\n", array[k], k);
|
|
||||||
// k++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Copy remaining elements of leftArray[], if any
|
|
||||||
// while (i < n1) {
|
|
||||||
// array[k] = leftArray[i];
|
|
||||||
// System.out.printf("Placing %d at index %d\n", array[k], k);
|
|
||||||
// i++;
|
|
||||||
// k++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Copy remaining elements of rightArray[], if any
|
|
||||||
// while (j < n2) {
|
|
||||||
// array[k] = rightArray[j];
|
|
||||||
// System.out.printf("Placing %d at index %d\n", array[k], k);
|
|
||||||
// j++;
|
|
||||||
// k++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Display the merged array
|
|
||||||
// System.out.printf("Merged array from index %d to %d: ", left, right);
|
|
||||||
// printArray(array, left, right);
|
|
||||||
// System.out.println();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static void merge(int[] arr, int low, int mid, int high, int currentLevel) {
|
public static void merge(int[] arr, int low, int mid, int high, int currentLevel) {
|
||||||
ArrayList<Integer> temp = new ArrayList<>(); // temporary array
|
ArrayList<Integer> temp = new ArrayList<>(); // temporary array
|
||||||
int left = low; // starting index of left half of arr
|
int left = low; // starting index of left half of arr
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue