Skip to content

Instantly share code, notes, and snippets.

@trbhoang
Created February 3, 2023 03:01
Show Gist options
  • Select an option

  • Save trbhoang/55839f459693dc53a6f8f59fe1a4a86c to your computer and use it in GitHub Desktop.

Select an option

Save trbhoang/55839f459693dc53a6f8f59fe1a4a86c to your computer and use it in GitHub Desktop.
#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