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 63 64 65 66 67 68
|
/* tree.cc */
#include <cstdio>
#include "utils.h"
#include "tree.h"
node::node(void) {
parent = NULL;
subs = NULL;
}
void node::split(int nsubs)
{
#if USE_MALLOC
subs = xmalloc(sizeof(node*) * nsubs);
#else
subs = new node*[nsubs];
#endif
}
cell::cell(void)
{
type = CELL;
}
body::body(void)
{
type = BODY;
}
void tree::print(void)
{
print_tree(root);
}
void tree::print_tree(node *t)
{
static int level = 0;
if (t != NULL) {
if (t->type == BODY)
printf("%*s" "body: \n", level, "");
else if (t->type == CELL)
printf("%*s" "cell: \n", level, "");
if (t->subs != NULL) {
level++;
for (int i = 0; i < NSUBS; i++)
print_tree(t->subs[i]);
}
}
}
body * newbody(void)
{
#if USE_MALLOC
return (body *) xmalloc(sizeof(body));
#else
return new body();
#endif
}
cell * newcell(void)
{
#if USE_MALLOC
return (cell *) xmalloc(sizeof(cell));
#else
return new cell();
#endif
}
|