Let's say your current programming project is using a circular queue implementation which uses a simple modulus operation for moving the head and tail forward: p = (p+1)%n. But the queue isn't a purely traditional one and you sometimes have to move backwards during a search. When this search wraps from the front to the rear, you must use this code: p = (p==0?n-1:p-1). One day programmer Sam comes up with this little gem: p=(p+d)%n. Here d is filled in with 1 when moving forward and n-1 when moving backwards. Can Sam's simple solution be correct? Prove or disprove Sam here.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here