title: Binary tree: insert node algorithm
body: <p>I'm trying to implement a Binary tree (is not important if it's general binary tree, or binary search tree) and I'm having some troubles with the function that creates a node and link it into the tree.<br />
  This is the code I've written so far:</p>
  
  <pre><code>class BinaryTree {
      class Node {
          char data;
  
          Node* leftChild;
          Node* rightChild;
  
          Node(char d, Node* lc, Node* rc):
              data(d), leftChild(lc), rightChild(rc) {}
      } *head;
      int treeSize;
  public:
      BinaryTree(): head(0), treeSize(0) {}
  
      // totally wrong code
      void createNode(char dat) {
          if (head-&gt;data &lt; dat)
              head-&gt;leftChild = new Node(dat, 0, 0);
          if (head-&gt;rightChild == 0)
              head-&gt;rightChild = new Node(dat, 0, 0);
          if (head == 0) {
              head = new Node(dat, head, head);
          }
      }
  };
  </code></pre>
  
  <p>Well, I thought to implement the binary tree using a linked list, but in this case the problem will be that the <code>head</code> pointer will point to one of the last added node, not to the root. Another issue using linked list in this way could be to <em>find</em> an empty child of a node where to add a new node.<br />
  There's someone that could help me and maybe suggest a better way to implement the Binary tree?<br />
  <br />
  Note: I planned to make this class a <code>template</code>, char is just for try it on the fly.</p>