diff -r 8b7c98b7acaac42034eff0ebee63d7b143841e26 -r aae1d6bbd33b56fe4ba8c784a9c68ea1fdc1ff64 cpp/algorithms/algorithms.vcxproj
--- a/cpp/algorithms/algorithms.vcxproj Sun Feb 17 18:50:14 2013 -0600
+++ b/cpp/algorithms/algorithms.vcxproj Tue Feb 19 23:47:40 2013 -0600
@@ -20,9 +20,11 @@
+
+
diff -r 8b7c98b7acaac42034eff0ebee63d7b143841e26 -r aae1d6bbd33b56fe4ba8c784a9c68ea1fdc1ff64 cpp/algorithms/algorithms.vcxproj.filters
--- a/cpp/algorithms/algorithms.vcxproj.filters Sun Feb 17 18:50:14 2013 -0600
+++ b/cpp/algorithms/algorithms.vcxproj.filters Tue Feb 19 23:47:40 2013 -0600
@@ -50,5 +50,11 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
\ No newline at end of file
diff -r 8b7c98b7acaac42034eff0ebee63d7b143841e26 -r aae1d6bbd33b56fe4ba8c784a9c68ea1fdc1ff64 cpp/algorithms/src/Node.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cpp/algorithms/src/Node.h Tue Feb 19 23:47:40 2013 -0600
@@ -0,0 +1,54 @@
+#ifndef NODE_H
+#define NODE_H
+
+#define null 0
+
+#include
+#include
+
+template
+class Node
+{
+private:
+ Node * createNode(T obj)
+ {
+ Node * newnode = new Node(obj);
+ newnode->parent = this;
+ return newnode;
+ }
+
+ void initVars()
+ {
+ this->parent = 0;
+ this->left = 0;
+ this->right = 0;
+ }
+public:
+ Node(T obj) { this->object = obj; initVars(); }
+ T object;
+ Node * parent;
+ Node * left;
+ Node * right;
+
+ Node * addLeft(T obj)
+ {
+ if (this->left != null)
+ throw std::string("Left is not null!");
+ this->left = createNode(obj);
+ }
+
+ Node * addRight(T obj)
+ {
+ if (this->right != null)
+ throw std::string("Right is not null!");
+ this->right = createNode(obj);
+ }
+
+ void addLeftRight(T left, T right)
+ {
+ this->addLeft(left);
+ this->addRight(right);
+ }
+};
+
+#endif
\ No newline at end of file
diff -r 8b7c98b7acaac42034eff0ebee63d7b143841e26 -r aae1d6bbd33b56fe4ba8c784a9c68ea1fdc1ff64 cpp/algorithms/src/Tree.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cpp/algorithms/src/Tree.h Tue Feb 19 23:47:40 2013 -0600
@@ -0,0 +1,97 @@
+#ifndef TREE_H
+#define TREE_H
+
+#include "Node.h"
+#include
+
+template
+class Tree
+{
+private:
+ void _DeleteTree(Node * node)
+ {
+ cout << "Killing node: " << node->object << endl;
+ if (node->left != null)
+ _DeleteTree(node->left);
+ if (node->right != null)
+ _DeleteTree(node->right);
+ delete node;
+ node = null;
+ }
+public:
+ Node * root;
+
+ void DeleteTree()
+ {
+ this->_DeleteTree(root);
+ }
+ Tree(Node * root)
+ {
+ this->root = root;
+ }
+ ~Tree()
+ {
+ //DeleteTree(root);
+ }
+
+ std::vector *> getBoundary()
+ {
+ std::vector *> edges;
+ edges.push_back(root);
+ std::vector *> tmp;
+ tmp = getLeftEdges(root->left);
+ edges.insert(edges.end(), tmp.begin(), tmp.end());
+ tmp = getRightEdges(root->right);
+ edges.insert(edges.end(), tmp.begin(), tmp.end());
+ return edges;
+ }
+
+ std::vector *> getLeftEdges(Node * nodes)
+ {
+ std::vector *> ret;
+ if (nodes == null)
+ return ret;
+ if (nodes->parent->right == nodes) //if the node is a right child
+ {
+ //add current node
+ if (nodes->right == null && nodes->left == null)
+ ret.push_back(nodes);
+ }
+ else if (nodes->parent->left == nodes) // if the node is a left child
+ {
+ ret.push_back(nodes);
+ }
+ std::vector *> tmp;
+ tmp = getLeftEdges(nodes->left);
+ ret.insert(ret.end(), tmp.begin(), tmp.end());
+ tmp = getLeftEdges(nodes->right);
+ ret.insert(ret.end(), tmp.begin(), tmp.end());
+ return ret;
+ }
+
+ std::vector *> getRightEdges(Node * nodes)
+ {
+ std::vector *> ret;
+ if (nodes == null)
+ return ret;
+
+ std::vector *> tmp;
+ tmp = getRightEdges(nodes->left);
+ ret.insert(ret.end(), tmp.begin(), tmp.end());
+ tmp = getRightEdges(nodes->right);
+ ret.insert(ret.end(), tmp.begin(), tmp.end());
+ if (nodes->parent->right == nodes) //if the node is a right child
+ {
+ //add current node
+ ret.push_back(nodes);
+ }
+ else if (nodes->parent->left == nodes) // if the node is a left child
+ {
+ if (nodes->right == null && nodes->left == null)
+ ret.push_back(nodes);
+ }
+ return ret;
+ }
+};
+
+#endif
\ No newline at end of file
diff -r 8b7c98b7acaac42034eff0ebee63d7b143841e26 -r aae1d6bbd33b56fe4ba8c784a9c68ea1fdc1ff64 cpp/algorithms/src/main.cpp
--- a/cpp/algorithms/src/main.cpp Sun Feb 17 18:50:14 2013 -0600
+++ b/cpp/algorithms/src/main.cpp Tue Feb 19 23:47:40 2013 -0600
@@ -9,19 +9,43 @@
#include "QuickSort.h"
#include "MergeSort.h"
#include "BinarySearch.h"
+#include "Node.h"
+#include "Tree.h"
using namespace std;
int main()
{
- MergeSort sort1;
- //sort1.initContainer(create_vector("test")("test2"));
+ /*//sort1.initContainer(create_vector("test")("test2"));
//cout << sort1.ToString();
//vector arr1 = create_vector(
+ MedianSort sort1;
sort1.initContainer(create_vector(3)(2)(4)(3)(1));
sort1.Sort();
cout << sort1.ToString() << endl;
- BinarySearch search1;
- search1.initContainer(sort1.getContainer());
- cout << search1.Search(7) << endl;
+ //BinarySearch search1;
+ //search1.initContainer(sort1.getContainer());
+ //cout << search1.Search(7) << endl;*/
+ Node * root = new Node(30);
+ Node * l = root->addLeft(20);
+ Node * r = root->addRight(40);
+ l->addLeft(10)->addLeftRight(5,15);
+ l->addRight(25)->addRight(28);
+ r->addLeft(35);
+ r->addRight(50)->addRight(41);
+ Tree tree(root);
+ vector *> nodes = tree.getBoundary();
+ for(size_t i = 0; i < nodes.size(); i++)
+ {
+ cout << nodes[i]->object << " ";
+ }
+ cout << endl;
+ tree.DeleteTree();
+ //root->addRight(
+ //root->left
+ //Tree t(root);
+
+
+
+ //delete root;
}
\ No newline at end of file