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...


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.



Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here