forked from umang-jain/hacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deque.py
65 lines (59 loc) · 1.51 KB
/
deque.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Deque():
def __init__(self):
self.items = []
def addFront(self, item):
self.items.insert(0, item)
def addRear(self, item):
self.items.append(item)
def removeFront(self):
return self.items.pop(0)
def removeRear(self):
return self.items.pop()
def displaydeque(self):
for i in reversed(self.items):
print(i)
def isEmpty(self):
return self.items == []
def size(self):
return len(self.items)
def main():
deq = Deque()
deq.addFront(1)
deq.addFront(2)
deq.addFront(3)
deq.addFront(4)
deq.addRear("z")
deq.displaydeque()
print("\n\n\n")
deq.removeRear()
deq.removeRear()
deq.removeFront()
deq.displaydeque()
if __name__ == "__main__":
main()
def palindromeDEQUE(message):
deqObj = Deque()
message = message.lower()
for msg in message:
deqObj.addRear(msg)
i=0
length = deqObj.size()
while deqObj.size() > 1:
front = deqObj.removeFront()
end = deqObj.removeRear()
if(front != end):
return False
#if (front == end):
# if(deqObj.size() > 1): #or (front==None) or (end==None)):
# return True
# continue
# else:
# break
# return True
return True
print(palindromeDEQUE("racecar"))
print(palindromeDEQUE("notapali"))
print(palindromeDEQUE("madam"))
print(palindromeDEQUE("anna"))
print(palindromeDEQUE("noon"))
print(palindromeDEQUE("test"))