-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.txt
94 lines (88 loc) · 1.79 KB
/
11.txt
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
// Read the marks obtained by students of second year in an online examination of particular subject.
Find out maximum and minimum marks obtained in that subject. Use heap data structure. Analyze
the algorithm.
#include<iostream>
using namespace std;
class hp
{
int heap[20],heap1[20],marks,student,i;
public:
hp()
{
heap[0]=0; heap1[0]=0;
}
void getdata();
void insert1(int heap[],int);
void upadjust1(int heap[],int);
void insert2(int heap1[],int);
void upadjust2(int heap1[],int);
void minmax();
};
void hp::getdata()
{
cout<<"\n enter the no. of students";
cin>>student;
cout<<"\n enter the marks";
for(i=0;i<student;i++)
{
cin>>marks;
insert1(heap,marks);
insert2(heap1,marks);
}
}
void hp::insert1(int heap[20],int x)
{
int n;
n=heap[0];
heap[n+1]=marks;
heap[0]=n+1;
upadjust1(heap,n+1);
}
void hp::upadjust1(int heap[20],int i)
{
int temp;
while(i>1&&heap[i]>heap[i/2])
{
temp=heap[i];
heap[i]=heap[i/2];
heap[i/2]=temp;
i=i/2;
}
}
void hp::insert2(int heap1[20],int marks)
{
int n;
n=heap1[0];
heap1[n+1]=marks;
heap1[0]=n+1;
upadjust2(heap1,n+1);
}
void hp::upadjust2(int heap1[20],int i)
{
int temp1;
while(i>1&&heap1[i]<heap1[i/2])
{
temp1=heap1[i];
heap1[i]=heap1[i/2];
heap1[i/2]=temp1;
i=i/2;
}
}
void hp::minmax()
{
cout<<"\n max marks"<<heap[1];
cout<<"\n##";
for(i=0;i<=student;i++)
{ cout<<"\n"<<heap[i]; }
cout<<"\n min marks"<<heap1[1];
cout<<"\n##";
for(i=0;i<=student;i++)
{ cout<<"\n"<<heap1[i]; }
}
int main()
{
hp h;
h.getdata();
h.minmax();
return 0;
}