fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. void DisCountSort(vector<int> &arr, int n)
  8. {
  9. auto _max = max_element(arr.begin(), arr.end());
  10. int max_val = *_max;
  11. arr.clear(); // begin to sort arr
  12. vector<int> c(max_val + 1, 0); // number of times that index value appears
  13. for (int i = 0; i < n; ++i) c[arr[i]] += 1;
  14. auto it = arr.begin();
  15. for (int i = 0; i < max_val + 1; ++i) {
  16. if (c[i] > 0) {
  17. arr.insert(it, c[i], i);
  18. it = arr.end();
  19. }
  20.  
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. vector<int> arr;
  27. for (int i = 0; i < 1000111; i++)
  28. arr.push_back(1);
  29. DisCountSort(arr, arr.size());
  30. cout << "DONE SORTING" << endl;
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
DONE SORTING