Add RD of MaxHeap implementation
This commit is contained in:
46
cpp/datastructs/maxheap/maxheap.h
Normal file
46
cpp/datastructs/maxheap/maxheap.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*#############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
|
||||
## About: An example of a max heap implementation ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################
|
||||
## maxheap.h
|
||||
*/
|
||||
|
||||
#ifndef MAXHEAP_H
|
||||
#define MAXHEAP_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define ROOT 1
|
||||
|
||||
class MaxHeap {
|
||||
|
||||
public:
|
||||
MaxHeap();
|
||||
MaxHeap(const MaxHeap& rhs);
|
||||
MaxHeap(int _size);
|
||||
~MaxHeap();
|
||||
const MaxHeap& operator=(const MaxHeap& rhs);
|
||||
void insert(int val);
|
||||
void del();
|
||||
void print();
|
||||
void makeEmpty();
|
||||
int findMax();
|
||||
int findMin();
|
||||
bool isEmpty();
|
||||
bool isFull();
|
||||
|
||||
private:
|
||||
void insert(int*& heap, int _size, int val);
|
||||
void del(int* heap);
|
||||
void print(int* heap, int _index);
|
||||
void grow(int*& heap, int _size);
|
||||
void siftUp(int* heap, int _index);
|
||||
void siftDown(int* heap, int currentMax);
|
||||
int size, index;
|
||||
int *heap;
|
||||
};
|
||||
|
||||
#endif //MAXHEAP_H
|
||||
Reference in New Issue
Block a user