-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeap.cpp
89 lines (85 loc) · 1.1 KB
/
Heap.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
#include<iostream>
using namespace std;
class heap
{
private:
int *top;
int height;
int size;
int index;
int value;
public:
heap()
{
cout<<"Enter Of Which Size You Want to create a heap:: ";
cin>>height;
size=pow(2,height);
top=new int[size];
index=1;
}
void insertheap()
{
cout<<"Please Enter The Value to Insert";
cin>>value;
top[index]=value;
if(index<2)
{
index++;
return;
}
else
{int temp=index;
while(temp!=1)
{
temp=temp/2;
if(top[temp]>top[index])
{
int t;
t=top[temp];
top[temp]=top[index];
top[index]=t;
}
}
index++;
return;
}
}
void deleteheap()
{
int temp=2;
index--;
top[1]=top[index];
while(temp!=index)
{
if(top[1]>top[temp])
{
int t=top[1];
top[1]=top[temp];
top[temp]=t;
temp=temp*2;
}
}
}
void print()
{
cout<<endl;
for(int i=1;i<index;i++)
{
cout<<top[i]<<endl;
}
}
void percolatedwon()
{
}
}h1;
int main()
{
h1.insertheap();
h1.insertheap();
h1.insertheap();
h1.insertheap();
h1.insertheap();
h1.insertheap();
h1.insertheap();
h1.print();
}