-
Notifications
You must be signed in to change notification settings - Fork 20k
Add Double Ended Heap #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
add doubleEndedHeap
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.
Good Work! I have some requests
Double exponent = Math.floor(Math.log(pos + 1) / Math.log(2)) - 1; | ||
int temp = (int) (pos + Math.pow(2, exponent)); | ||
// Return the parent of the index location if there is no partner | ||
if (temp > elements) |
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 use curly brackets. For example
if (temp > elements) {
// something
}
see http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html#449
|
||
// Insert key at index at position in min-heap | ||
private void minInsert(int at, int key) { | ||
for (int parent; (parent = (at - 1) / 2) != 0 && key < deap[parent]; deap[at] = deap[parent], at = parent) |
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.
Can you simplify this for-loop ? Write a while loop with a certain condition.
|
||
// Insert key at index at position in max-heap | ||
private void maxInsert(int at, int key) { | ||
for (int parent; (parent = (at - 1) / 2) != 0 && key > deap[parent]; deap[at] = deap[parent], at = parent) |
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.
The same thing above.
* the larger value in the leaf node and store the temp in the larger value. | ||
*/ | ||
int bigminPartner = 0; | ||
if (deap[minPartner(i)] > deap[2 * minPartner(i) + 1] && deap[minPartner(i)] > deap[2 * minPartner(i) + 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.
Break this line of max. 80 columns
A double-ended priority queue (DEPQ) or double-ended heap is a data structure similar to a priority queue or heap, but allows for efficient removal of both the maximum and minimum, according to some ordering on the keys (items) stored in the structure. Every element in a DEPQ has a priority or value. In a DEPQ, it is possible to remove the elements in both ascending as well as descending order.