MCPcopy Create free account
hub / github.com/SR-Sunny-Raj/Hacktoberfest2021-DSA / Decrease_key

Method Decrease_key

16. Heap/FibonacciHeap.cpp:286–318  ·  view source on GitHub ↗

Decrease Key Operation

Source from the content-addressed store, hash-verified

284
285// Decrease Key Operation
286int 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
321int FibonacciHeap::Cut(node *H1, node *x, node *y)

Callers 1

mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected