title: Try to BST Sort using template in C++ but didn't work while using random string to test
body: <p>I am trying to creat binary Search Tree then traversal by in-order to sort with template in C++ but  there is something wrong when testing with random string array.</p>
  
  <p>It working all properly when I test with  random integer array, but unfortunately it shows error message <code>No matching function for call to 'insert</code> while using string instead of integer.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &lt;ctime&gt;
  using namespace std;
  
  struct Node
  {
      int key;
      struct Node *left, *right;
  };
  
  struct Node *newNode(int item)
  {
      struct Node *temp = new Node;
      temp-&gt;key = item;
      temp-&gt;left = temp-&gt;right = NULL;
      return temp;
  }
  
  template &lt;typename T&gt; void storeSorted(Node *root, T *arr, int &amp;i)
  {
      if (root != NULL)
      {
          storeSorted(root-&gt;left, arr, i);
          arr[i++] = root-&gt;key;
          storeSorted(root-&gt;right, arr, i);
      }
  }
  
  Node* insert(Node* node, int key)
  {
      if (node == NULL) return newNode(key);
      if (key &lt; node-&gt;key)
          node-&gt;left  = insert(node-&gt;left, key);
      else if (key &gt; node-&gt;key)
          node-&gt;right = insert(node-&gt;right, key);
      return node;
  }
  
  template &lt;typename T&gt; void treeSort(T *arr, int n)
  {
      struct Node *root = NULL;
      root = insert(root, arr[0]);
      for (int i=1; i&lt;n; i++)
          insert(root, arr[i]);
      int i = 0;
      storeSorted(root, arr, i);
  }
  
  string *stringData(int length) {
    srand(time(NULL));
    string *data = new string[length];
    const char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (int j = 0; j &lt; length; j++) {
      for (int k = 0; k &lt; 6; k++)
        data[j] += alphabet[rand() % strlen(alphabet)];
    }
    return data;
  }
  
  int main()
  {
      int n = 100;
      string *arr = stringData(n);
      treeSort(arr, n);
      for (int i=0; i&lt;n; i++)
         cout &lt;&lt; arr[i] &lt;&lt; " ";
      system("PAUSE");
      return 0;
  }
  
  </code></pre>