-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
added Binary Heap #3959
added Binary Heap #3959
Conversation
public: | ||
BinaryHeap() | ||
{} | ||
void Insert(int element); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please name variables with camelCase.
void BinaryHeap::DeleteMin(){ | ||
|
||
if (heap.size() == 0){ | ||
std::cout << "Heap is Empty"<< std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please raise an exception instead.
int BinaryHeap::left(int parent){ | ||
int l = 2 * parent + 1; | ||
|
||
if (l < heap.size()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use a single line ternary for this whole function.
|
||
// Return Parent | ||
int BinaryHeap::parent(int child){ | ||
int p = (child - 1)/2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here and in the previous 2 functions.
Fixes issue:
Changes:
Binary Heap
with its C++ implementation.