-
Notifications
You must be signed in to change notification settings - Fork 0
/
Min_Heap.h
39 lines (35 loc) · 829 Bytes
/
Min_Heap.h
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
#ifndef MIN_HEAP_H
#define MIN_HEAP_H
#include <iostream>
#include <cassert>
#include <vector>
#define edl '\n'
template <class type>
class Min_Heap
{
type *array{};
int size{};
int capacity{1}; // we made capacity trick like vector;
int left(int pos);
int right(int pos);
int parent(int pos);
void heapify_up(int child_pos);
void heapify_down(int parent_pos);
void heapify();
bool is_heap(int parent_pos);
void expand_capacity();
public:
Min_Heap();
Min_Heap(const std::vector<type> &vec);
~Min_Heap();
void push(type val);
void pop();
type top();
const int get_size();
bool is_empty();
void print_less_than(type val, int pos = 0);
bool is_heap_array(type *p, int n);
void heap_sort(type *p, int n);
bool search(type val);
};
#endif