Created
February 3, 2023 03:01
-
-
Save trbhoang/55839f459693dc53a6f8f59fe1a4a86c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cstdlib> | |
| void sort(char* array[], int size) { | |
| char* chars = *array; | |
| int counts[26] = {0}; | |
| for (auto i = 0; i < size; i++) { | |
| counts[int(chars[i] - 'A') % 26]++; | |
| } | |
| int j = 0; | |
| for (auto i = 0; i < 26; i++) { | |
| while (counts[i] > 0) { | |
| chars[j] = 'A' + i; | |
| counts[i]--; | |
| j++; | |
| } | |
| } | |
| } | |
| int main() { | |
| int size = 500000; | |
| char* array_of_chars = new char(size); | |
| for (auto i = 0; i < size; i++) { | |
| array_of_chars[i] = 'A' + rand() % 26; | |
| } | |
| sort(&array_of_chars, size); | |
| for (auto i = 0; i < size; i++) { | |
| std::cout << array_of_chars[i]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment