Example #1
0
void release_tree(const struct _node <int> *r)
{
    if (r == NULL)
        return;
    release_tree(r->l);
    release_tree(r->r);
    delete r;
}
Example #2
0
static INPparseNode *
mkfirst(INPparseNode *fst, INPparseNode *snd)
{
    if(fst) {
        fst->usecnt ++;
        release_tree(snd);
        fst->usecnt --;
    } else {
        release_tree(snd);
    }

    return fst;
}
Example #3
0
int C_try_binary_search_tree::init_tree()
{
	if (root != 0)
		release_tree();

	return 0;
}
Example #4
0
int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cout << "usage: ./a7 file" << std::endl;
        return -1;
    }

    // get input text
    std::ifstream f(argv[1]);

    std::string s;
    std::vector<std::string> lines;

    while (!f.eof()) {
        s = "";
        std::getline(f, s);
        if (!s.empty()) lines.push_back(s);
    }

    f.close();

    // create a list of symbols
    std::vector<symbol> A;
    symbols(lines.begin(), lines.end(), std::back_inserter(A));

    // process the list (student's code)

    bnode<symbol>* tree = huffman_tree(A.begin(), A.end());

    // print dictionary
    print_dictionary(std::cout, tree);

    // free memory (student's code)
    release_tree(tree);
    // print dictionary
    print_dictionary(std::cout, tree);


    return 0;
} // main