Document 3
Document 3
Document 3
#include <iostream>
#define MAX_TREE_HT 50
struct MinHNode {
unsigned freq;
char item;
};
struct MinH {
unsigned size;
unsigned capacity;
};
temp->item = item;
temp->freq = freq;
return temp;
}
// Create min heap using given capacity
minHeap->size = 0;
minHeap->capacity = capacity;
return minHeap;
int i;
// Swap function
*a = *b;
*b = t;
// Heapify
smallest = left;
smallest = right;
if (smallest != idx) {
swapMinHNode(&minHeap->array[smallest],
&minHeap->array[idx]);
minHeapify(minHeap, smallest);
// Check if size if 1
--minHeap->size;
minHeapify(minHeap, 0);
return temp;
// Insertion
++minHeap->size;
int i = minHeap->size - 1;
i = (i - 1) / 2;
minHeap->array[i] = minHeapNode;
int n = minHeap->size - 1;
int i;
minHeapify(minHeap, i);
}
struct MinH *createAndBuildMinHeap(char item[], int freq[], int size) {
minHeap->size = size;
buildMinHeap(minHeap);
return minHeap;
while (!checkSizeOne(minHeap)) {
left = extractMin(minHeap);
right = extractMin(minHeap);
top->left = left;
top->right = right;
insertMinHeap(minHeap, top);
return extractMin(minHeap);
}
void printHCodes(struct MinHNode *root, int arr[], int top) {
if (root->left) {
arr[top] = 0;
if (root->right) {
arr[top] = 1;
if (isLeaf(root)) {
printArray(arr, top);
// Wrapper function
int main() {