Skip to content

Commit 7b17ead

Browse files
chore: improve FibonacciHeap (#5251)
1 parent a5b4c61 commit 7b17ead

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class FibonacciHeap {
88
private static int totalCuts = 0;
99
private int numOfTrees = 0;
1010
private int numOfHeapNodes = 0;
11-
private int markedHeapNoodesCounter = 0;
11+
private int markedHeapNodesCounter = 0;
1212

1313
/*
1414
* a constructor for an empty Heap
@@ -190,7 +190,7 @@ private void decreaseKey(HeapNode x, int delta) {
190190
* Potential = #trees + 2*#markedNodes
191191
*/
192192
public int potential() {
193-
return numOfTrees + (2 * markedHeapNoodesCounter);
193+
return numOfTrees + (2 * markedHeapNodesCounter);
194194
}
195195

196196
/**
@@ -232,7 +232,7 @@ private void cascadingCuts(HeapNode curr) {
232232
if (!curr.isMarked()) { // stop the recursion
233233
curr.mark();
234234
if (!curr.isRoot()) {
235-
this.markedHeapNoodesCounter++;
235+
this.markedHeapNodesCounter++;
236236
}
237237
} else {
238238
if (curr.isRoot()) {
@@ -252,7 +252,7 @@ private void cascadingCuts(HeapNode curr) {
252252
private void cut(HeapNode curr) {
253253
curr.parent.rank--;
254254
if (curr.marked) {
255-
this.markedHeapNoodesCounter--;
255+
this.markedHeapNodesCounter--;
256256
curr.marked = false;
257257
}
258258
if (curr.parent.child == curr) { // we should change the parent's child

src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public MaxHeap(List<HeapElement> listElements) {
2222
System.out.println("Null element. Not added to heap");
2323
}
2424
}
25-
if (maxHeap.size() == 0) {
25+
if (maxHeap.isEmpty()) {
2626
System.out.println("No element has been added, empty heap.");
2727
}
2828
}

src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public MinHeap(List<HeapElement> listElements) {
2222
System.out.println("Null element. Not added to heap");
2323
}
2424
}
25-
if (minHeap.size() == 0) {
25+
if (minHeap.isEmpty()) {
2626
System.out.println("No element has been added, empty heap.");
2727
}
2828
}

src/main/java/com/thealgorithms/datastructures/heaps/MinPriorityQueue.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
*/
1515
public class MinPriorityQueue {
1616

17-
private int[] heap;
18-
private int capacity;
17+
private final int[] heap;
18+
private final int capacity;
1919
private int size;
2020

21-
// calss the constructor and initializes the capacity
21+
// class the constructor and initializes the capacity
2222
MinPriorityQueue(int c) {
2323
this.capacity = c;
2424
this.size = 0;

0 commit comments

Comments
 (0)