chore: improve FibonacciHeap (#5251)
This commit is contained in:
parent
a5b4c6173f
commit
7b17ead902
@ -8,7 +8,7 @@ public class FibonacciHeap {
|
||||
private static int totalCuts = 0;
|
||||
private int numOfTrees = 0;
|
||||
private int numOfHeapNodes = 0;
|
||||
private int markedHeapNoodesCounter = 0;
|
||||
private int markedHeapNodesCounter = 0;
|
||||
|
||||
/*
|
||||
* a constructor for an empty Heap
|
||||
@ -190,7 +190,7 @@ public class FibonacciHeap {
|
||||
* Potential = #trees + 2*#markedNodes
|
||||
*/
|
||||
public int potential() {
|
||||
return numOfTrees + (2 * markedHeapNoodesCounter);
|
||||
return numOfTrees + (2 * markedHeapNodesCounter);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +232,7 @@ public class FibonacciHeap {
|
||||
if (!curr.isMarked()) { // stop the recursion
|
||||
curr.mark();
|
||||
if (!curr.isRoot()) {
|
||||
this.markedHeapNoodesCounter++;
|
||||
this.markedHeapNodesCounter++;
|
||||
}
|
||||
} else {
|
||||
if (curr.isRoot()) {
|
||||
@ -252,7 +252,7 @@ public class FibonacciHeap {
|
||||
private void cut(HeapNode curr) {
|
||||
curr.parent.rank--;
|
||||
if (curr.marked) {
|
||||
this.markedHeapNoodesCounter--;
|
||||
this.markedHeapNodesCounter--;
|
||||
curr.marked = false;
|
||||
}
|
||||
if (curr.parent.child == curr) { // we should change the parent's child
|
||||
|
@ -22,7 +22,7 @@ public class MaxHeap implements Heap {
|
||||
System.out.println("Null element. Not added to heap");
|
||||
}
|
||||
}
|
||||
if (maxHeap.size() == 0) {
|
||||
if (maxHeap.isEmpty()) {
|
||||
System.out.println("No element has been added, empty heap.");
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class MinHeap implements Heap {
|
||||
System.out.println("Null element. Not added to heap");
|
||||
}
|
||||
}
|
||||
if (minHeap.size() == 0) {
|
||||
if (minHeap.isEmpty()) {
|
||||
System.out.println("No element has been added, empty heap.");
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ package com.thealgorithms.datastructures.heaps;
|
||||
*/
|
||||
public class MinPriorityQueue {
|
||||
|
||||
private int[] heap;
|
||||
private int capacity;
|
||||
private final int[] heap;
|
||||
private final int capacity;
|
||||
private int size;
|
||||
|
||||
// calss the constructor and initializes the capacity
|
||||
// class the constructor and initializes the capacity
|
||||
MinPriorityQueue(int c) {
|
||||
this.capacity = c;
|
||||
this.size = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user