Skip to content

Commit 8bd3965

Browse files
author
codelogicws
committed
priority queue
remove was setting the value to 0 before returning the requested value.
1 parent 9274817 commit 8bd3965

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed
Binary file not shown.

src/ws/codelogic/algorithms/priorityqueue/BinaryTree.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public BinaryTree(Comparable[] emptyArray){
1717
public void add(Comparable element){
1818
elements[++indexOfLastElement] = element;
1919
swim(indexOfLastElement);
20+
debug();
2021
}
2122

2223
private void swim(int index) {
@@ -65,20 +66,11 @@ private boolean hasParent(int index) {
6566
public Comparable remove(){
6667
exchange(0, indexOfLastElement);
6768
sink(0);
68-
elements[indexOfLastElement] = 0;
6969
return elements[indexOfLastElement--];
7070
}
7171

7272
private void sink(int index){
73-
//DEBUG
74-
System.out.println("debug-BinaryTree: ");
75-
for(Comparable c : elements){
76-
System.out.println(c);
77-
}
78-
System.out.println("--------------");
79-
System.out.println(index + " " + child1(index));
80-
//DEBUG
81-
73+
debug();
8274
child1 = child1(index);
8375
child2 = child2(index);
8476

@@ -93,5 +85,15 @@ private int child2(int index){
9385
return child1(index)-1;
9486
}
9587

88+
private void debug(){
89+
//DEBUG
90+
System.out.println("debug-BinaryTree: ");
91+
for(Comparable c : elements){
92+
System.out.println(c);
93+
}
94+
System.out.println("--------------");
95+
//DEBUG
96+
}
97+
9698

9799
}

0 commit comments

Comments
 (0)