-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathA9.cpp
111 lines (85 loc) · 1.29 KB
/
A9.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include<iostream>
using namespace std;
class heap
{
int max,n1 = 0,n2 = 0;;
int *data1;
int *data2;
public:
heap(int max)
{
this->max = max;
data1 = new int[max + 1];
data2 = new int[max + 1];
}
void min_heap(int);
void max_heap(int);
void display();
};
void heap :: min_heap(int x)
{
int i;
if(n1 == max)
cout<<"ENTRIES ARE FULL"<<endl;
else
{
n1++;
for(i = n1;i >= 1;)
{
if(i == 1)
break;
if(x >= data1[i/2])
break;
else
{
data1[i] = data1[i/2];
i = i/2;
}
}
data1[i] = x;
}
}
void heap :: max_heap(int x)
{
int i;
if(n2 == max)
cout<<"ENTRIES ARE FULL"<<endl;
else
{
n2++;
for(i = n2;i >= 1;)
{
if(i == 1)
break;
if(x <= data2[i/2])
break;
else
{
data2[i] = data2[i/2];
i = i/2;
}
}
data2[i] = x;
}
}
void heap :: display()
{
cout<<"\nMINIMUM MARKS:"<<data1[1]<<endl;
cout<<"MAXIMUM MARKS:"<<data2[1]<<endl;
}
int main()
{
int no,marks;
cout<<"Enter the number of students"<<endl;
cin>>no;
heap h(no);
cout<<"Enter the marks"<<endl;
for(int i = 0;i<no;i++)
{
cin>>marks;
h.min_heap(marks);
h.max_heap(marks);
}
h.display();
return 0;
}