Decrease Key Operation
| 284 | |
| 285 | // Decrease Key Operation |
| 286 | int FibonacciHeap::Decrease_key(node *H1, int x, int k) |
| 287 | { |
| 288 | node *y; |
| 289 | if (H1 == NULL) |
| 290 | { |
| 291 | cout << "The Heap is Empty" << endl; |
| 292 | return 0; |
| 293 | } |
| 294 | node *ptr = Find(H1, x); |
| 295 | if (ptr == NULL) |
| 296 | { |
| 297 | cout << "Node not found in the Heap" << endl; |
| 298 | return 1; |
| 299 | } |
| 300 | |
| 301 | if (ptr->n < k) |
| 302 | { |
| 303 | cout << "Entered key greater than current key" << endl; |
| 304 | return 0; |
| 305 | } |
| 306 | ptr->n = k; |
| 307 | y = ptr->parent; |
| 308 | if (y != NULL && ptr->n < y->n) |
| 309 | { |
| 310 | Cut(H1, ptr, y); |
| 311 | Cascase_cut(H1, y); |
| 312 | } |
| 313 | |
| 314 | if (ptr->n < H->n) |
| 315 | H = ptr; |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | // Cutting Function |
| 321 | int FibonacciHeap::Cut(node *H1, node *x, node *y) |