klips/cpp/datastructs/maxheap/maxheap.h

47 lines
1.3 KiB
C
Raw Permalink Normal View History

2020-07-10 02:20:14 +00:00
/*#############################################################################
## 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();
2020-07-12 00:35:49 +00:00
MaxHeap operator=(MaxHeap rhs);
2020-07-10 02:20:14 +00:00
void insert(int val);
void del();
void print() const;
2020-07-10 02:20:14 +00:00
void makeEmpty();
int findMax() const;
int findMin() const;
bool isEmpty() const;
bool isFull() const;
2020-07-10 02:20:14 +00:00
private:
void insert(int*& heap, int _size, int val);
void del(int* heap);
void print(int* heap, int _index) const;
2020-07-10 02:20:14 +00:00
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