-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA_10.cpp
More file actions
106 lines (103 loc) · 1.76 KB
/
Copy pathDSA_10.cpp
File metadata and controls
106 lines (103 loc) · 1.76 KB
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
#include<iostream>
#include<math.h>
using namespace std;
# define max1 20
class stud
{
public:
int marks[max1], total;
stud()
{
for(int i=0;i<max1;i++)
marks[i]=0;
}
void createHeap();
void displayHeap();
void showmax();
void showmin();
};
void stud::createHeap()
{
int i,j,par,temp,M;
cout<<"\n Enter How many Stu : ";
cin>>total; //5
for(i=0;i<total;i++) //0-4=5 times
{
cout<<"\n Enter Marks : ";
cin>>marks[i];
M=marks[i];
j=i;//j is child
par=floor((j-1)/2);
while(marks[j] < marks[par] && j!=0)
{
temp=marks[j];
marks[j]=marks[par];
marks[par]=temp;
j=par;
par=floor((j-1)/2);
}
cout<<"\n \n Current Heap : After Inserting : " <<M<<" is : \n ";
displayHeap();
}
}
void stud::displayHeap()
{
int i=0,space=6;
cout<<endl;
while(i<total)
{
if(i==0 || i==1 || i==3 || i==7 || i==15)
{
cout<<endl<<endl;
for(int j=0;j<space;j++)
cout<<" ";
space-=2;
}
cout<<" "<<marks[i];i++;
}
}
void stud::showmin()
{
cout<<marks[0];
}
void stud::showmax()
{
int max,i;
max=marks[0];
for(i=1;i<total;i++)
{
if(max < marks[i])
max=marks[i];
}
cout<<max;
}
int main()
{
stud s1;
int ch, ans;
do
{
cout<<"\n 1. Insert Marks ";
cout<<"\n 2. Display Marks ";
cout<<"\n 3. Show Max Marks ";
cout<<"\n 4. Show Min Marks ";
cout<<"\n\n Enter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1:
s1.createHeap();
break;
case 2:
s1.displayHeap();
break;
case 3: s1.showmax();
break;
case 4: s1.showmin();
break;
}
cout<<" \n Do u want to continue : (1 for continue )";
cin>>ans;
}while(ans==1);
return 0;
}