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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #ifndef TREE_H
  2. #define TREE_H
  3. #include "stdlib.h"
  4. #include "stdbool.h"
  5. typedef struct Node {
  6. struct Node *zero;
  7. struct Node *one;
  8. int index;
  9. } node;
  10. typedef struct Tree {
  11. node *root;
  12. int size;
  13. } tree;
  14. static inline bool isleaf(node *n) {return (n->zero == NULL && n->one == NULL);}
  15. static inline bool tisempty(tree *t) {return (t->root->zero == NULL && t->root->one == NULL);}
  16. static inline int tsize(tree *t) {return t->size;}
  17. static inline node *newn(int index) {
  18. node *n = (node*) malloc(sizeof(node));
  19. n->zero = NULL;
  20. n->one = NULL;
  21. n->index = index;
  22. return n;
  23. }
  24. static inline tree *newt() {
  25. tree *t = (tree*) malloc(sizeof(tree));
  26. t->root = newn(0);
  27. t->size = 0;
  28. return t;
  29. }
  30. #endif