-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
65 lines (53 loc) · 845 Bytes
/
Copy pathTest.cpp
File metadata and controls
65 lines (53 loc) · 845 Bytes
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
61
62
63
64
65
#include <iostream>
using namespace std;
struct Maxheap
{
int *arr;
int size, capacity;
Maxheap(int capacity)
{
this->capacity = capacity;
size = 0;
arr = new int(capacity);
}
int parent(int i)
{
return ((i - 1) / 2);
}
void insert(int marks)
{
if (size == capacity)
{
cout << "overflow";
return;
}
size++;
arr[size - 1] = marks;
int i = size - 1;
while (i != 0 and (arr[parent(i)] < arr[i]))
{
swap(arr[i], arr[parent(i)]);
i = parent(i);
}
}
};
int main()
{
int n;
cout << "Enter number of students: ";
cin >> n;
Maxheap heap(n);
for (int i = 0; i < n; i++)
{
int marks;
cout << "Enter marks: ";
cin >> marks;
heap.insert(marks);
}
cout << "\nMaxheap: ";
for (int i = 0; i < n; i++)
{
cout << heap.arr[i] << " ";
}
cout << "\nHighest marks: " << heap.arr[0];
}