-
Notifications
You must be signed in to change notification settings - Fork 0
/
minHeap.h
45 lines (31 loc) · 898 Bytes
/
minHeap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef _MINHEAP_H_
#define _MINHEAP_H_
#include <stdio.h>
#include <stdlib.h>
/* Reusing HW 6 Min Heap Functionality -
* Vertex = ASCII CHAR INT REPRESENTATION
* DIST = # APPEARANCES IN THE TEXT
*/
typedef struct HeapNode{
int vertex;
int dist;
struct HeapNode *left,*right;
} HeapNode;
typedef struct MinHeap{
int size;
int capacity;
int *pos;
HeapNode **array;
} MinHeap;
HeapNode *create_node(int v, int d);
MinHeap *create_heap(int capacity);
void swapNodes(HeapNode** a, HeapNode** b);
void Heapify(MinHeap* heap, int id);
HeapNode *removeSmallest(MinHeap *heap);
void adjustDistInHeap(MinHeap *heap, int vertex, int distance);
void heapInsert(MinHeap *heap, HeapNode *node);
void HeapifyEntire(MinHeap* heap);
int isLeaf(HeapNode *node);
void prepareHeap(MinHeap *heap, int *frequency, int size);
HeapNode *buildHuffmanTree(MinHeap *heap);
#endif