I've been playing around with it a bit but...
So with the example "SPOON"
U queue: SPOON (the original one, you fill it back up again which gets confusing)
R queue: NOOPS (should be this way but it's not)
so you empty U out and put SPOON back into it again in the process of making R
u.first() vs. r.first() S vs N not the same, toggle your boolean and we say it's not a palindrome
"NOON"
U : NOON
R : NOON
u.first() vs. r.first() N vs. N check
Update U to OON (by your delete step)
Update R to OON
u.first vs r.first O vs. O check
etc.
boolean remains true, so it's a palindrome
But....your reversing technique is taking the front of of one queue and putting it into the back of another, so they're sharing the same order, so you're testing bobr vs. bobr instead of bobr vs. rbob. What we really need to do is get the back element of a queue (which we can), put it into another (which we can) and pop off the back element and get the next to last (which we cannot).
What I think you should do (like I had started to mention before) is split your string, so NOON would become NO and ON. Flip around ON and enqueue it as NO, now you can compare the two. If you have a string with an odd number of letters or numbers, 10001, take 10 throw out 0 and keep 01. Enqueue 01 backwards as 10 (where you can just take the last character of the string as the first and march until the middle). Phew. Anyway, I might be on later but I've got some stuff to finish up so give it a try. It won't be too much overhauling, just with the strings.
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
Offline 4,271 posts
since Sep 2009