-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuff_tree_node.c
More file actions
42 lines (38 loc) · 820 Bytes
/
Copy pathhuff_tree_node.c
File metadata and controls
42 lines (38 loc) · 820 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "huff_tree_node.h"
huff_tree_node* new_node(int c, int freq){
huff_tree_node* new = malloc(sizeof(huff_tree_node));
new->ch = c;
new->freq = freq;
new->left = NULL;
new->right = NULL;
return new;
}
//Is node1 smaller than node2 ?
bool compare_node(huff_tree_node* node1, huff_tree_node* node2){
if(node1->freq == node2->freq){
if(node1->ch < node2->ch){
return true;
} else {
return false;
}
} else if (node1->freq <node2->freq){
return true;
} else {
return false;
}
}
void free_node(huff_tree_node* node){
free(node);
}
void free_huff_tree(huff_tree_node* head){
if(head->left) {
free_huff_tree(head->left);
}
if(head->right) {
free_huff_tree(head->right);
}
free(head);
}