Click here to Skip to main content
15,891,033 members
Articles / Desktop Programming / MFC

Tree Container Library

Rate me:
Please Sign up or sign in to vote.
4.85/5 (29 votes)
22 Aug 2007Zlib10 min read 229.3K   7.2K   111  
A generic template class library for storing data in a tree-like structure.
#pragma once

#include "Alpha.h"

struct testNode
{
	testNode(char& _ch) : ch(_ch) {}

	void operator() (const Alpha& elem) 
	{
		assert(*elem.get_text().begin() == ch++);
	}

private:
	char& ch;
};


bool is_a_vowel(const Alpha& elem)
{
	std::string chr = elem.get_text();
	return chr == "A" || chr == "I" || chr == "O" || chr == "E" || chr == "U";
}

bool comp_if_vowel(const Alpha& lhs, const Alpha& rhs) { return is_a_vowel(lhs) && is_a_vowel(rhs); }



struct set_rank
{
	void operator() (Alpha& elem) { elem.set_ranking(*elem.get_text().begin() - 'A');}
};


struct add_one
{
	Alpha operator() (Alpha& elem) { elem.set_text(elem.get_text() + "1"); return elem; }
};



struct gen_alpha
{
	gen_alpha(char _ch) : ch(_ch) {}

	Alpha operator() () 
	{
		std::ostringstream ostr;
		ostr << ch++;
		return Alpha(ostr.str());
	}
private:
	char ch;
};


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License



Comments and Discussions