Advertisement
kolbka_

Untitled

Feb 13th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4.  
  5. void sort(char* array[], int size) {
  6. const int RANGE = 26;
  7. std::vector<int> count(RANGE);
  8. for (int i = 0; i < size; i++) {
  9. count[*(*array + i) - 'A']++;
  10. }
  11.  
  12. int j = 0;
  13. for (int i = 0; i < RANGE; i++) {
  14. while (count[i]--) {
  15. *(*array + j++) = i + 'A';
  16. }
  17. }
  18. }
  19.  
  20.  
  21. int main() {
  22. int size = 500000;
  23. char* array_of_chars = new char[size];
  24. for (auto i = 0; i < size; i++) {
  25. array_of_chars[i] = 'A' + rand() % 26;
  26. }
  27.  
  28. sort(&array_of_chars, size);
  29.  
  30. for (auto i = 0; i < size; i++) {
  31. std::cout << array_of_chars[i];
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement