-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deque.py
47 lines (33 loc) · 978 Bytes
/
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
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 20 17:20:27 2016
@author: pengcheng
"""
class Deque:
def __init__(self):
self.items=[]
def isEmpty(self):
return self.items==[]
def addFront(self, item):
self.items.append(item)
def addRear(self, item):
self.items.insert(0,item)
def removeFront(self):
return self.items.pop()
def removeRear(self):
return self.items.pop(0)
def size(self):
return len(self.items)
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("lsdkjfskr"))
print (palchecker("radar"))