I am loading a set of integers int a binary which is no problem, its when Im trying to increase their frequencies I am running into some difficulties. As it stands the program crashs if any of the numbers repeat themselves, any suggestions?

void BST::insert(int d)
    tree_node* t = new tree_node;
    tree_node* parent;
    t->data = d;
    t->freq = 1;
    t->left = NULL;
    t->right = NULL;
    parent = NULL;
    bool found = false;
    // is this a new tree?
    root = t; 
        found = search(d);
          t->freq=t->freq + 1;
             //insertions are as leaf nodes
             tree_node* curr;
             curr = root;
             // Find the Node's parent
                 parent = curr;
                 if(t->data > curr->data) 
                 curr = curr->right;
                 else curr = curr->left;

        if(t->data < parent->data)
           parent->left = t;
           parent->right = t;

bool BST::search(int d)
tree_node * t = root;
bool found = false;
while (!found && t!=0)
      if (d < t->data) // descend left
      t = t->left;
      else if (t->data < d) // descend right
      t = t->right;
      else // item found
      found = true;
 return found;

Your logic seems false.

Line 3: You create a node t
Line 16: You search for the int value then then updated t's frequency? But t is a new node not necessarily inside the binary tree!

What you want is a helper function that returns the Node who has the value x. Then increment that node's frequency.

tree_node * _find(const tree_node& root,const int val){
 if(!tree_node) return NULL;
 else if(val > root.value()) _find( root.rightNode(),val);
 else if(val < root.value()) _find( root.leftNode(),val);
 else{ return root; /* found */ }

void insert(int val){
  tree_node *n = _find(val);
  if(n != NULL){
    /* added previously, so just updated count */
      /* not found */
      _insertHelper( val ); //just inserts a new node with val into the tree
This article has been dead for over six months. Start a new discussion instead.