findHighest.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Link to challenge: https://edabit.com/challenge/LNtD7xK33ncfEYDYv
#include <iostream>
#include <vector>
class Highest{
private:
struct node{
int data;
node* next;
};
node* head = nullptr;
public:
Highest();
Highest(std::vector<int> arr){
for (int i = 0; i < arr.size(); i++){
if (head == nullptr){
head = new node{arr[i], nullptr};
}
else{
head = new node{arr[i], head};
}
}
}
int findHighest(){
int biggest = 0;
for (node* i = head; i != nullptr; i = i -> next){
if (i -> data > biggest){
biggest = i -> data;
}
}
return biggest;
}
void printArr(std::vector<int> arr){
for (int i = 0; i < arr.size(); i++){
std::cout << arr[i] << " ";
}
}
void printResult(){
std::cout << findHighest() << std::endl;
}
};
int main(){
Highest v1({-1, 3, 5, 6, 99, 12, 2});
v1.printResult();
Highest v2({0, 12, 4, 87});
v2.printResult();
Highest v3({6, 7, 8});
v3.printResult();
return 0;
}
Console Output
1
2
3
99
87
8