0% found this document useful (0 votes)
3 views3 pages

Fib Bonacci

The document contains C code for implementing a Fibonacci heap data structure. It includes functions for creating the heap, inserting nodes, and finding the minimum key. The main function demonstrates the insertion of several keys and retrieves the minimum key from the heap.

Uploaded by

madhugowdaks.iet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Fib Bonacci

The document contains C code for implementing a Fibonacci heap data structure. It includes functions for creating the heap, inserting nodes, and finding the minimum key. The main function demonstrates the insertion of several keys and retrieves the minimum key from the heap.

Uploaded by

madhugowdaks.iet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stdio.

h>
#include<stdlib.h>
#include<limits.h>
#include<math.h>

typedef struct Node {


int key;
int degree;
struct Node *parent;
struct Node *child;
struct Node *left;
struct Node *right;
int mark;
} Node;

typedef struct Heap {


Node *min;
int n;
} Fheap;

Fheap *createHeap() {
Fheap *heap = (Fheap *)malloc(sizeof(Fheap));
heap->min = NULL;
heap->n = 0;
return heap;
}

Node *createNode(int key) {


Node *node = (Node *)malloc(sizeof(Node));
node->key = key;
node->degree = 0;
node->parent = node->child = NULL;
node->left = node->right = node;
node->mark = 0;
return node;
}
void insertNode(Fheap *heap, Node *node) {
if (heap->min == NULL) {
heap->min = node;
} else {
node->left = heap->min;
node->right = heap->min->right;
heap->min->right->left = node;
heap->min->right = node;
if (node->key < heap->min->key) {
heap->min = node;
}
}
heap->n++;
}

void insert(Fheap *heap, int key) {


Node *node = createNode(key);
insertNode(heap, node);
}

int findmin(Fheap *heap) {


if (heap->min == NULL) {
printf("Heap is empty!\n");
return INT_MAX;
}
return heap->min->key;
}

int main() {
Fheap *heap = createHeap();
insert(heap, 75);
insert(heap, 3);
insert(heap, 17);
insert(heap, 24);
printf("Minimum key: %d\n", findmin(heap));
return 0;
}

You might also like