summaryrefslogtreecommitdiff
path: root/lib/HTree.cc
blob: c651f48acff3104b91c32577eebeaadc5e121436 (plain)
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
#include <stdio.h>
#include <iostream.h>
#include "config.h"
#include "HTree.h"

HTree::HTree(int n_freq, char * n_objet) {
  freq = n_freq;
  objet = n_objet;
  left = right = NULL;
}

HTree::HTree(HTree * n_left, HTree * n_right) {
  left = n_left;
  right = n_right;
  freq = n_left->freq + n_right->freq;
  objet = NULL;
}

HTree::~HTree() {
  if (left) delete left;
  if (right) delete right;
}

ostream & HTree::Trace(ostream & os, int d) {
  static char cmpr[MAX_HDEPTH + 1];
  if (objet) {
    cmpr[d] = '\0';
    os << objet << " = " << cmpr << endl;
  } else {
    if (left) {
      cmpr[d] = '0';
      left->Trace(os, d + 1);
    }
    if (right) {
      cmpr[d] = '1';
      right->Trace(os, d + 1);
    }
  }
  return os;
}