Created
May 31, 2014 15:48
-
-
Save hillscottc/ee04f082b0023037263b to your computer and use it in GitHub Desktop.
A Palindrome Checker Using Deque (palchecker)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pythonds.basic.deque import Deque | |
def palchecker(aString): | |
chardeque = Deque() | |
for ch in aString: | |
chardeque.addRear(ch) | |
stillEqual = True | |
while chardeque.size() > 1 and stillEqual: | |
first = chardeque.removeFront() | |
last = chardeque.removeRear() | |
if first != last: | |
stillEqual = False | |
return stillEqual | |
print(palchecker("lsdkjfskf")) | |
print(palchecker("radar")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment