Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. for (int i=1; i<=n; i++)
  2. {
  3. double c = sqrt(i)/sqrt(n);
  4. b[i]=c;
  5. cout<<c<<endl;
  6. }
  7.  
  8. void bucketSort(vector<double> &arr, int n)
  9. {
  10. // 1) Create n empty buckets
  11. vector<double> b[n];
  12.  
  13. //fnid the ring and set bucket
  14. for (int i=1; i<=n; i++)
  15. {
  16. double c = sqrt(i)/sqrt(n);
  17. b[i]=c;
  18. cout<<c<<endl;
  19. }
  20.  
  21. // 2) Put array elements in different buckets
  22. for (int i=0; i<n; i++)
  23. {
  24. int bi = n*arr[i]; // Index in bucket
  25. b[bi].push_back(arr[i]);
  26. }
  27.  
  28. // 3) Sort individual buckets
  29. for (int i=0; i<n; i++)
  30. {
  31. sort(b[i].begin(), b[i].end());
  32. }
  33.  
  34. // 4) Concatenate all buckets into arr[]
  35. int index = 0;
  36. for (int i = 0; i < n; i++)
  37. {
  38. for (int j = 0; j < b[i].size(); j++)
  39. {
  40. arr[index++] = b[i][j];
  41. }
  42. }
  43. }
  44.  
  45. /* Driver program to test above funtion */
  46. int main()
  47. {
  48. vector<double> A;
  49.  
  50. double numbers;
  51.  
  52. while (cin>>numbers)
  53. {
  54. A.push_back(numbers);
  55. }
  56.  
  57. int n = A.size();
  58. bucketSort(A, n);
  59. cout<<"Sort numbers: "<<endl;
  60.  
  61. for (int i=0; i<n; i++)
  62. {
  63. cout<<A[i]<<" ";
  64. }
  65. }
  66.  
  67. bucketSort_2.cpp:19:6: error: no match for 'operator=' (operand types are 'std::vector<double>' and 'double')
  68. b[i]=c;
  69. ^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement