1#include <bits/stdc++.h>
2using namespace std;
3
4int main(){
5 const int size = 10;
6 int k = 3; //Can be any number smalled than size
7 int array[size] = {5,2,8,34,73,82,1,6,19,29};
8 sort(array,array+size);
9 int smallestKthElement = array[k-1];
10 int largestKthElement = array[size-k];
11}
1def divideAndConquer_Max(arr, ind, len):
2 maximum = -1;
3
4 if (ind >= len - 2):
5 if (arr[ind] > arr[ind + 1]):
6 return arr[ind];
7 else:
8 return arr[ind + 1];
9
10
11 maximum = divideAndConquer_Max(arr, ind + 1, len);
12
13 if (arr[ind] > maximum):
14 return arr[ind];
15 else:
16 return maximum;
17
18
19def divideAndConquer_Min(arr, ind, len):
20 minimum = 0;
21 if (ind >= len - 2):
22 if (arr[ind] < arr[ind + 1]):
23 return arr[ind];
24 else:
25 return arr[ind + 1];
26
27 minimum = divideAndConquer_Min(arr, ind + 1, len);
28
29 if (arr[ind] < minimum):
30 return arr[ind];
31 else:
32 return minimum;
33
34
35if __name__ == '__main__':
36
37 minimum, maximum = 0, -1;
38
39 # array initialization
40 arr = [6, 4, 8, 90, 12, 56, 7, 1, 63];
41
42 maximum = divideAndConquer_Max(arr, 0, 9);
43 minimum = divideAndConquer_Min(arr, 0, 9);
44
45 print("The minimum number in the array is: ", minimum);
46 print("The maximum number in the array is: ", maximum);
1
2function nthlargest(arra,highest){
3 var x = 0,
4 y = 0,
5 z = 0,
6 temp = 0,
7 tnum = arra.length,
8 flag = false,
9 result = false;
10
11 while(x < tnum){
12 y = x + 1;
13
14 if(y < tnum){
15 for(z = y; z < tnum; z++){
16
17 if(arra[x] < arra[z]){
18 temp = arra[z];
19 arra[z] = arra[x];
20 arra[x] = temp;
21 flag = true;
22 }else{
23 continue;
24 }
25 }
26 }
27
28 if(flag){
29 flag = false;
30 }else{
31 x++;
32 if(x === highest){
33
34 result = true;
35 }
36 }
37 if(result){
38 break;
39 }
40 }
41
42 return (arra[(highest - 1)]);
43 }
44
45console.log(nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4));
46
47