You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
722 B

#ifndef TREE_H
#define TREE_H
#include "stdlib.h"
#include "stdbool.h"
typedef struct Node {
struct Node *zero;
struct Node *one;
int index;
} node;
typedef struct Tree {
node *root;
int size;
} tree;
static inline bool isleaf(node *n) {return (n->zero == NULL && n->one == NULL);}
static inline bool tisempty(tree *t) {return (t->root->zero == NULL && t->root->one == NULL);}
static inline int tsize(tree *t) {return t->size;}
static inline node *newn(int index) {
node *n = (node*) malloc(sizeof(node));
n->zero = NULL;
n->one = NULL;
n->index = index;
return n;
}
static inline tree *newt() {
tree *t = (tree*) malloc(sizeof(tree));
t->root = newn(0);
t->size = 0;
return t;
}
#endif