Remove unnecassary variable usage.

(cherry picked from commit ca51ac0ecea9fd1dfd3d957e77f95aa8e0f467bb)
This commit is contained in:
Emrullah YILDIRIM 2020-10-04 14:10:08 +03:00
parent 88858555de
commit eb3fc306c3

View File

@ -97,7 +97,6 @@ public final class ClosestPair {
final Location[] a, final int first, final int last) { final Location[] a, final int first, final int last) {
Location pivot = a[last]; // pivot Location pivot = a[last]; // pivot
int pIndex = last;
int i = first - 1; int i = first - 1;
Location temp; // Temporarily store value for position transformation Location temp; // Temporarily store value for position transformation
for (int j = first; j <= last - 1; j++) { for (int j = first; j <= last - 1; j++) {
@ -110,8 +109,8 @@ public final class ClosestPair {
} }
i++; i++;
temp = a[i]; // array[pivot] <-> array[i] temp = a[i]; // array[pivot] <-> array[i]
a[i] = a[pIndex]; a[i] = a[last];
a[pIndex] = temp; a[last] = temp;
return i; // pivot index return i; // pivot index
} }
@ -128,7 +127,6 @@ public final class ClosestPair {
final Location[] a, final int first, final int last) { final Location[] a, final int first, final int last) {
Location pivot = a[last]; // pivot Location pivot = a[last]; // pivot
int pIndex = last;
int i = first - 1; int i = first - 1;
Location temp; // Temporarily store value for position transformation Location temp; // Temporarily store value for position transformation
for (int j = first; j <= last - 1; j++) { for (int j = first; j <= last - 1; j++) {
@ -141,8 +139,8 @@ public final class ClosestPair {
} }
i++; i++;
temp = a[i]; // array[pivot] <-> array[i] temp = a[i]; // array[pivot] <-> array[i]
a[i] = a[pIndex]; a[i] = a[last];
a[pIndex] = temp; a[last] = temp;
return i; // pivot index return i; // pivot index
} }
@ -194,11 +192,10 @@ public final class ClosestPair {
Location[] divideArray = new Location[indexNum]; Location[] divideArray = new Location[indexNum];
System.arraycopy(a, 0, divideArray, 0, indexNum); // Copy previous array System.arraycopy(a, 0, divideArray, 0, indexNum); // Copy previous array
int totalNum = indexNum; // number of coordinates in the divideArray
int divideX = indexNum / 2; // Intermediate value for divide int divideX = indexNum / 2; // Intermediate value for divide
Location[] leftArray = new Location[divideX]; //divide - left array Location[] leftArray = new Location[divideX]; //divide - left array
//divide-right array //divide-right array
Location[] rightArray = new Location[totalNum - divideX]; Location[] rightArray = new Location[indexNum - divideX];
if (indexNum <= 3) { // If the number of coordinates is 3 or less if (indexNum <= 3) { // If the number of coordinates is 3 or less
return bruteForce(divideArray); return bruteForce(divideArray);
} }
@ -206,20 +203,20 @@ public final class ClosestPair {
System.arraycopy(divideArray, 0, leftArray, 0, divideX); System.arraycopy(divideArray, 0, leftArray, 0, divideX);
//divide-right array //divide-right array
System.arraycopy( System.arraycopy(
divideArray, divideX, rightArray, 0, totalNum - divideX); divideArray, divideX, rightArray, 0, indexNum - divideX);
double minLeftArea = 0; //Minimum length of left array double minLeftArea = 0; //Minimum length of left array
double minRightArea = 0; //Minimum length of right array double minRightArea = 0; //Minimum length of right array
double minValue = 0; //Minimum lengt double minValue = 0; //Minimum lengt
minLeftArea = closestPair(leftArray, divideX); // recursive closestPair minLeftArea = closestPair(leftArray, divideX); // recursive closestPair
minRightArea = closestPair(rightArray, totalNum - divideX); minRightArea = closestPair(rightArray, indexNum - divideX);
// window size (= minimum length) // window size (= minimum length)
minValue = Math.min(minLeftArea, minRightArea); minValue = Math.min(minLeftArea, minRightArea);
// Create window. Set the size for creating a window // Create window. Set the size for creating a window
// and creating a new array for the coordinates in the window // and creating a new array for the coordinates in the window
for (int i = 0; i < totalNum; i++) { for (int i = 0; i < indexNum; i++) {
double xGap = Math.abs(divideArray[divideX].x - divideArray[i].x); double xGap = Math.abs(divideArray[divideX].x - divideArray[i].x);
if (xGap < minValue) { if (xGap < minValue) {
ClosestPair.setSecondCount(secondCount + 1); // size of the array ClosestPair.setSecondCount(secondCount + 1); // size of the array
@ -232,7 +229,7 @@ public final class ClosestPair {
// new array for coordinates in window // new array for coordinates in window
Location[] firstWindow = new Location[secondCount]; Location[] firstWindow = new Location[secondCount];
int k = 0; int k = 0;
for (int i = 0; i < totalNum; i++) { for (int i = 0; i < indexNum; i++) {
double xGap = Math.abs(divideArray[divideX].x - divideArray[i].x); double xGap = Math.abs(divideArray[divideX].x - divideArray[i].x);
if (xGap < minValue) { // if it's inside a window if (xGap < minValue) { // if it's inside a window
firstWindow[k] = divideArray[i]; // put in an array firstWindow[k] = divideArray[i]; // put in an array