-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathforest.h
58 lines (49 loc) · 1.08 KB
/
forest.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
46
47
48
49
50
51
52
53
54
55
56
57
58
/****************************************************************************
* forest.h
*
* Computer Science 50
* Problem Set 6
*
* Defines a forest for Huffman trees.
***************************************************************************/
#ifndef FOREST_H
#define FOREST_H
#include "tree.h"
/**
* Space for a tree in a forest.
*/
typedef struct plot
{
Tree* tree;
struct plot* next;
}
Plot;
/**
* A forest for Huffman trees, implemented as a singly linked list.
*/
typedef struct forest
{
Plot* first;
}
Forest;
/**
* Makes a forest, initially barren, returning pointer thereto
* or NULL on error.
*/
Forest* mkforest(void);
/**
* Removes a tree with lowest weight from the forest, returning
* pointer thereto or NULL if forest is barren.
*/
Tree* pick(Forest* f);
/**
* Plants a tree in the forest, provided that tree's frequency is non-0.
* Returns true on success and false on error.
*/
bool plant(Forest* f, Tree* t);
/**
* Deletes a forest (and all of its trees).
* Returns true on success and false on error.
*/
bool rmforest(Forest* f);
#endif