Much easier to get algorithms from _Collected Algorithms of the ACM_. All sorts of interesting (and nasty) problems like yours have published solutions. I have implemented a version with non-repeating characters and I believe I remember one with repeating characters.