Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n_used_chars = 0;
- int chars[256], loc_of_char[256];
- for (int i = 0; i < 256; i++) used_chars[i] = loc_of_char[i] = i;
- for (int i = 0; i < string_length; i++) {
- char c = string[i];
- int loc = loc_of_char[c];
- if (loc >= n_used_chars) {
- // Character c has not been used before. Swap it down to the used set.
- chars[loc] = chars[n_used_chars];
- loc_of_char[chars[loc]] = loc;
- chars[n_used_chars] = c;
- loc_of_chars[c] = n_used_chars++;
- }
- }
- // At this point chars[0..n_used_chars - 1] contains all the used chars.
- // and chars[n_used_chars..255] contains the unused ones!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement