title: how to make bucket sort to sort negative numbers in c++
body: <p>I just finished the bucket sort, it works fine without a for function:</p>
  
  <pre><code>for (int i=1; i&lt;=n; i++)
      {
      double c = sqrt(i)/sqrt(n);
      b[i]=c;
      cout&lt;&lt;c&lt;&lt;endl;
      }
  </code></pre>
  
  <p>but what I wan to do with this function is try to find the radii and set to the bucket. How what should I edit for it? Thanks for your view. Here is the whole code:</p>
  
  <pre><code>    void bucketSort(vector&lt;double&gt; &amp;arr, int n)
      {
      // 1) Create n empty buckets
      vector&lt;double&gt; b[n];
  
      //fnid the ring and set bucket
      for (int i=1; i&lt;=n; i++)
      {
      double c = sqrt(i)/sqrt(n);
      b[i]=c;
      cout&lt;&lt;c&lt;&lt;endl;
      }
  
      // 2) Put array elements in different buckets
      for (int i=0; i&lt;n; i++)
      {
         int bi = n*arr[i]; // Index in bucket
         b[bi].push_back(arr[i]);
      }
  
      // 3) Sort individual buckets
      for (int i=0; i&lt;n; i++)
      {
         sort(b[i].begin(), b[i].end());
      }
  
      // 4) Concatenate all buckets into arr[]
      int index = 0;
      for (int i = 0; i &lt; n; i++)
      {
          for (int j = 0; j &lt; b[i].size(); j++)
      {
            arr[index++] = b[i][j];
      }
      }
  }
  
  /* Driver program to test above funtion */
  int main()
  {
      vector&lt;double&gt; A;
  
      double numbers;
  
      while (cin&gt;&gt;numbers)
      {
      A.push_back(numbers);
      }
  
      int n = A.size();
      bucketSort(A, n);
      cout&lt;&lt;"Sort numbers: "&lt;&lt;endl;
  
      for (int i=0; i&lt;n; i++)
      {
      cout&lt;&lt;A[i]&lt;&lt;" ";
      }
  }
  </code></pre>
  
  <p>Here is the out put:</p>
  
  <pre><code>bucketSort_2.cpp:19:6: error: no match for 'operator=' (operand types are 'std::vector&lt;double&gt;' and 'double')
    b[i]=c;
        ^
  </code></pre>