title: Binary Search Tree key/value pair - I know the value but not the key C++
body: <p>I have a simple question that I am confused about. I know what is the concept of having a key/value pair in a Binary Search Tree and how the tree looks like when it is built.</p>
  
  <p>What I am unsure is of how to search for a value in such a BST if I have no track of what its key would be?</p>
  
  <p>For example:</p>
  
  <p>Let say I have a binary search tree full of integers (as values) and also unique integers (as keys). And let say I want to count the number of times a specific integer (lets say: 200) occurs in this BST. So what I know, 200 is the "value" and not the "key".
  Hence I dont know the key at all. </p>
  
  <p>How can I search now for all the "200"s in the whole BST?
  Does it become a simple BST now and I dont need the key at all? But again, the tree is arranged to the left child and the right child using the "key" and not the value.</p>
  
  <p>I can also give you a code sample of how I initialize the BST:</p>
  
  <pre><code>void insertNode(TreeNode *&amp;p, int key, int value)
  {
    if (p == NULL) {
      p = new TreeNode;
      p-&gt;key = key;
      p-&gt;value = value;
      p-&gt;left = NULL;
      p-&gt;right = NULL;
      return;
    }
  
    if (key &lt; p-&gt;key)
      insertNode(p-&gt;left, key, value);
    else
      insertNode(p-&gt;right, key, value);
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>