| 55 | } |
| 56 | |
| 57 | public FibNode<T> insert(T value, double weight) |
| 58 | { |
| 59 | //FIB-HEAP-INSERT |
| 60 | @SuppressWarnings("unchecked") |
| 61 | FibNode<T> x = new FibNode(value, weight); |
| 62 | x.p = null; |
| 63 | x.child = null; |
| 64 | |
| 65 | if(min == null) |
| 66 | { |
| 67 | //6| create a root list for H containing just x |
| 68 | // H = new ArrayList<FibNode<T>>(); |
| 69 | // H.add(x); |
| 70 | //7| H.min D x |
| 71 | min = x; |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | //8| insert x into H ’s root list |
| 76 | min = merge(min, x);//9 & 10 handled implicitly by the behavior of merge method |
| 77 | } |
| 78 | //11| H.n = H.n+1 |
| 79 | this.n++; |
| 80 | |
| 81 | return x; |
| 82 | } |
| 83 | |
| 84 | public static <T> FibHeap<T> union(FibHeap<T> A, FibHeap<T> B) |
| 85 | { |