-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.cpp
More file actions
63 lines (57 loc) · 1.1 KB
/
Copy pathTree.cpp
File metadata and controls
63 lines (57 loc) · 1.1 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#define _CRT_SECURE_NO_WARNINGS
#include "Tree.h"
#include "Node.h"
#include <stdio.h>
#include <stdlib.h>
void createTree( Node * node, Tree *t)
{
//Tree *pnew = (Tree *)malloc(sizeof(Tree));
int node1 = node->tree.countRoot;
int node2 = node->pnext->tree.countRoot;
//t->code[0] = "";
t->table.letter = NULL;
t->table.count = NULL;
t->countRoot = node1 + node2;;
t->left = &node->tree;
t->right = &(node->pnext->tree);
add2List(&node,t);
deleteFirst(node);
deleteFirst(node);
}
void in(Tree *root)
{
if (root)
{
in(root->left);
printf("letter: %c Code %s", root->table.letter, root->code);
printf("\n");
in(root->right);
}
}
void makeCodes(Tree *root)
{
if (root->left)
{
strcpy(root->left->code, root->code);
strcat(root->left->code, "0");
makeCodes(root->left);
}
if (root->right)
{
strcpy(root->right->code, root->code);
strcat(root->right->code, "1");
makeCodes(root->right);
}
}
void inL(Tree *root, char letter)
{
if (root)
{
inL(root->left,letter);
if (root->table.letter==letter)
{
printf("%s", root->code);
}
inL(root->right, letter);
}
}