-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab3Q1.cpp
44 lines (42 loc) · 804 Bytes
/
Lab3Q1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*Input: nums = [3,2,1,5,6,4], k = 2
Output: 5
*/
/*Q1* test case Input: nums = [3,2,3,1,2,4,5,5,6], k = 2
Output: 5
*/
// #include<bits/stdc++.h>
#include<iostream>
using namespace std;
void insertionSort(int arr[], int n)
{
int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
void printArray(int arr[], int n)
{
int i;
for (i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
}
int main()
{
int arr[] = {0,-6,-5,-3,-2,1};
int N = sizeof(arr) / sizeof(arr[0]);
insertionSort(arr, N);
printArray(arr, N);
if (N >= 9) {
cout << "fourth highest number: " << arr[N - 9] << endl;
} else {
cout << "NO second highest no..." << endl;
}
return 0;
}