Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created October 16, 2012 16:46
Show Gist options
  • Save AeroNotix/3900481 to your computer and use it in GitHub Desktop.
Save AeroNotix/3900481 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
template <class T>
class Tree {
public:
~Tree();
T Value;
Tree<T> *Left;
Tree<T> *Right;
};
template <class T>
Tree<T>::~Tree() {
delete Left;
delete Right;
}
template <class T>
Tree<T> *NewNode(T i) {
Tree<T> *t = new Tree<T>;
t->Value = i;
t->Left = nullptr;
t->Right = nullptr;
return t;
}
template <class T>
class BinaryTree {
public:
BinaryTree();
~BinaryTree();
void Add(T);
vector<T> Walk();
unsigned int Levels() const;
private:
unsigned int levels;
Tree<T> *root;
void add(T i, Tree<T>* &leaf);
vector<T> walk(Tree<T> *leaf, vector<T>&);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment