Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void trickleDown(Node<T> trickle) {
- boolean go = true;
- while (go) {
- if (trickle.getLeftChild() == null && trickle.getRightChild() == null) {
- System.out.println("Stop please");
- go = false;
- } else if (trickle.getLeftChild() != null && trickle.getRightChild() != null) {
- if (trickle.getLeftChild().getPriority() > trickle.getRightChild().getPriority()) {
- if (trickle.getPriority() > trickle.getLeftChild().getPriority()) {
- go = false;
- } else {
- // swap the left child with current
- // create temp values of trickle
- T value = trickle.getValue();
- int priority = trickle.getPriority();
- // set trickle values to leftchilds
- trickle.setPriority(trickle.getLeftChild().getPriority());
- trickle.setValue(trickle.getLeftChild().getValue());
- // set trickle's child to temp vals
- trickle.getLeftChild().setValue(value);
- trickle.getLeftChild().setPriority(priority);
- trickle = trickle.getLeftChild();
- }
- } else if (trickle.getLeftChild().getPriority() < trickle.getRightChild().getPriority()) {
- if (trickle.getPriority() > trickle.getRightChild().getPriority()) {
- go = false;
- } else {
- // swap the left child with current
- // create temp values of trickle
- T value = trickle.getValue();
- int priority = trickle.getPriority();
- // set trickle values to Rightchilds
- trickle.setPriority(trickle.getRightChild().getPriority());
- trickle.setValue(trickle.getRightChild().getValue());
- // set trickle's child to temp vals
- trickle.getRightChild().setValue(value);
- trickle.getRightChild().setPriority(priority);
- trickle = trickle.getRightChild();
- }
- }
- } else if (trickle.getRightChild() == null && trickle.getLeftChild() != null) {
- if (trickle.getPriority() > trickle.getLeftChild().getPriority()) {
- go = false;
- } else {
- // swap the left child with current
- // create temp values of trickle
- T value = trickle.getValue();
- int priority = trickle.getPriority();
- // set trickle values to leftchilds
- trickle.setPriority(trickle.getLeftChild().getPriority());
- trickle.setValue(trickle.getLeftChild().getValue());
- // set trickle's child to temp vals
- trickle.getLeftChild().setValue(value);
- trickle.getLeftChild().setPriority(priority);
- trickle = trickle.getLeftChild();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement