Repository navigation
Add Double Ended Heap - #341
Closed
JeonSeongBae wants to merge 2 commits into
Closed
JeonSeongBae wants to merge 2 commits into
JeonSeongBae wants to merge 2 commits into
Conversation
add doubleEndedHeap
christianbender
requested changes
Mar 29, 2018
christianbender
left a comment
There was a problem hiding this comment.
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.
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.
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) |
| * 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.
Break this line of max. 80 columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.