My assignment was to come up with a palindrome program in python. Which I did here
def isPalindrome(word):
for i in range(len(word)//2):
if word[i] != word[-1-i]:
return False
return True
print (isPalindrome("maam")) #returns TRUE
print (isPalindrome("madam")) #returns TRUE
print (isPalindrome("hello")) #returns FALSE
print (isPalindrome("macdam")) #returns FALSE
print (isPalindrome("buffalolaffub")) #returns TRUE
print (isPalindrome("argentina")) #returns FALSE
Now my instructor wants this to be converted using Stack
s. Can anybody help with this?
Here's the Stack
data structure I have:
class Stack:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[len(self.items)-1]
def size(self):
return len(self.items)