import
java.util.*;
import
java.lang.*;
class
parallel_array_java {
static
int
partition(String first_name[],
String last_name[],
int
height[],
int
low,
int
high)
{
int
pivot = height[high];
int
i = (low -
1
);
for
(
int
j = low; j <= high -
1
; j++) {
if
(height[j] <= pivot) {
i++;
String temp = first_name[i];
first_name[i] = first_name[j];
first_name[j] = temp;
temp = last_name[i];
last_name[i] = last_name[j];
last_name[j] = temp;
int
temp1 = height[i];
height[i] = height[j];
height[j] = temp1;
}
}
String temp = first_name[i +
1
];
first_name[i +
1
] = first_name[high];
first_name[high] = temp;
temp = last_name[i +
1
];
last_name[i +
1
] = last_name[high];
last_name[high] = temp;
int
temp1 = height[i +
1
];
height[i +
1
] = height[high];
height[high] = temp1;
return
(i +
1
);
}
static
void
quickSort(String first_name[],
String last_name[],
int
height[],
int
low,
int
high)
{
if
(low < high) {
int
pi = partition(first_name, last_name,
height, low, high);
quickSort(first_name, last_name, height,
low, pi -
1
);
quickSort(first_name, last_name, height,
pi +
1
, high);
}
}
static
void
binarySearch(String first_name[],
String last_name[],
int
height[],
int
value,
int
n)
{
int
low =
0
, high = n -
1
;
int
index;
while
(low <= high) {
index = (high + low) /
2
;
if
(height[index] ==
158
) {
System.out.println(
"Person having height"
+
" 158 cms is "
+ first_name[index] +
" "
+ last_name[index]);
return
;
}
else
if
(height[index] >
158
)
high = index -
1
;
else
low = index +
1
;
}
System.out.print(
"Sorry, no such person"
+
" with height"
);
System.out.println(
"158 cms is found in"
+
" the record"
);
}
static
void
printParallelArray(String first_name[],
String last_name[],
int
height[],
int
n)
{
System.out.print(
"Name of people in increasing"
+
" order of"
);
System.out.println(
"their height: "
);
for
(
int
i =
0
; i < n; i++) {
System.out.println(first_name[i] +
" "
+ last_name[i] +
" has height "
+ height[i] +
" cms"
);
}
System.out.println();
}
public
static
void
main(String args[])
{
int
n =
10
;
String[] first_name = {
"Bones"
,
"Welma"
,
"Frank"
,
"Han"
,
"Jack"
,
"Jinny"
,
"Harry"
,
"Emma"
,
"Tony"
,
"Sherlock"
};
String[] last_name = {
"Smith"
,
"Seger"
,
"Mathers"
,
"Solo"
,
"Jackles"
,
"Weasly"
,
"Potter"
,
"Watson"
,
"Stark"
,
"Holmes"
};
int
[] height = {
169
,
158
,
201
,
183
,
172
,
152
,
160
,
163
,
173
,
185
};
quickSort(first_name, last_name, height,
0
, n -
1
);
printParallelArray(first_name, last_name,
height, n);
System.out.println(
"Name of the second tallest"
+
"person is "
+ first_name[n -
2
] +
" "
+ last_name[n -
2
]);
System.out.println(
"Name of the third shortest"
+
" person is "
+ first_name[
2
] +
" "
+ last_name[
2
]);
binarySearch(first_name, last_name, height,
158
, n);
}
}