Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. int n_used_chars = 0;
  2. int chars[256], loc_of_char[256];
  3. for (int i = 0; i < 256; i++) used_chars[i] = loc_of_char[i] = i;
  4.  
  5. for (int i = 0; i < string_length; i++) {
  6. char c = string[i];
  7. int loc = loc_of_char[c];
  8. if (loc >= n_used_chars) {
  9. // Character c has not been used before. Swap it down to the used set.
  10. chars[loc] = chars[n_used_chars];
  11. loc_of_char[chars[loc]] = loc;
  12. chars[n_used_chars] = c;
  13. loc_of_chars[c] = n_used_chars++;
  14. }
  15. }
  16. // At this point chars[0..n_used_chars - 1] contains all the used chars.
  17. // and chars[n_used_chars..255] contains the unused ones!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement