Hello.
With the help of the quick sorting method working by divide and conquer solve the following problem. "Nuts and bolts": An unorganized carpenter has a mixed set of N nuts and N bolts. The goal is to find the matching pair of nuts and bolts. Each nut corresponds exactly to one bolt, and each bolt corresponds exactly to one nut. By connecting the nut and the bolt to each other, the carpenter can learn more from them (however, he cannot directly compare two nuts or two bolts). Develop an algorithm for this task that uses an average of N log (N) comparisons.
Quick sort method:
private void quickSort(int[] array, int start, int end) { if (start >= end) return; int pivot = array[start]; int i = start; int j = end; int temp = 0; while (i <= j) { while (array[i] < pivot) { i++; } while (array[j] > pivot) { j--; } if (i <= j) { temp = array[i]; array[i] = array[j]; array[j] = temp; i++; j--; } } if (start < j) { quickSort(array, start, j); } if (i < end) { quickSort(array, i, end); } } I ask for help in solving the problem, I will be very grateful.