Skip to content
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

Merged
merged 3 commits into from
Mar 2, 2019
Merged

added Binary Heap #3959

merged 3 commits into from
Mar 2, 2019

Conversation

Bhupesh-V
Copy link
Contributor

Fixes issue:

Changes:

  • Added an New Data Structure Binary Heap with its C++ implementation.

public:
BinaryHeap()
{}
void Insert(int element);
Copy link
Member

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;
Copy link
Member

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())
Copy link
Member

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;
Copy link
Member

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.

@arnavb
Copy link
Member

arnavb commented Mar 2, 2019

djldk 2

@arnavb arnavb merged commit e1d0eb6 into OpenGenus:master Mar 2, 2019
@Bhupesh-V Bhupesh-V deleted the binary_heap branch March 6, 2019 05:34
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants