def test_size(self): """Test size method.""" d = Dequeue() self.assertEqual(d.size(), 0) n = 10 for number in range(1, n): d.add_rear(1) self.assertEqual(d.size(), number)
def test_size(self): d = Dequeue() self.assertEqual(d.size(), 0) d.add_front("apple") self.assertEqual(d.size(), 1) d.add_front("banana") self.assertEqual(d.size(), 2) d.add_front("cherry") self.assertEqual(d.size(), 3)
def balanced_parentheses(s): deq = Dequeue() for c in s: deq.pushBack(c) if b(deq.peekFront()) != b(deq.peekBack()): return False while deq.size() > 0: front = deq.popFront() while b(front) != b(deq.peekBack()) and deq.peekBack() != None: back = deq.popBack() back = deq.popBack() return deq.size() == 0 and b(front) == b(back)
def check_palindrome(text): D = Dequeue() for i in text: D.addBack(i) while D.size() > 1: if D.removeBack() == D.removeFront(): return False return True
def PalindromeDetector(string): dq = Dequeue() for letter in string: dq.add_rear(letter) while dq.size() > 1: if dq.remove_front() != dq.remove_rear(): return False return True
def palChecker(word): dq = Dequeue() for char in word: dq.addRear(char) while dq.size() > 1: if dq.removeFront() != dq.removeRear(): return False return True
def palchecker(str): d = Dequeue() for ch in str: d.addRear(ch) for _ in range(int(d.size() / 2)): if (d.removeFront() != d.removeRear()): return False return True
def check_palindrome(string_to_check): dq = Dequeue() dq.set_items(string_to_check) is_palindrome = True while dq.size() > 1: if dq.remove_front() != dq.remove_rear(): is_palindrome = False return is_palindrome
def palin_check(string): d=Dequeue() for ch in string: d.addRear(ch) equals=True while d.size()>1 and equals: if d.removeFront() is d.removeRear(): pass else: equals=False return equals
def checkPalindrome(input_string): dequeue = Dequeue() for character in input_string: dequeue.addRear(character) stillEqual = True while (dequeue.size() > 1 and stillEqual): first = dequeue.delFront() last = dequeue.delRear() if first != last: stillEqual = False return stillEqual
def check_palindrome(string_to_check): sanitised_string = re.sub("[^a-zA-Z]","", string_to_check).lower() dq = Dequeue() dq.set_items(sanitised_string) is_palindrome = True while dq.size() > 1: if dq.remove_front() != dq.remove_rear(): is_palindrome = False return is_palindrome
class PalindromeChecker: def __init__(self): self.dq = Dequeue() def check_if_palindrome(self, word): self.dq.items = list(word) is_palindrome = True while self.dq.size() > 1: first_letter = self.dq.remove_front() last_letter = self.dq.remove_rear() if first_letter != last_letter: is_palindrome = False return is_palindrome
def palindromeChecker(str): charDequeue = Dequeue() for ch in str: charDequeue.addRear(ch) stillEqual = True while charDequeue.size() > 1 and stillEqual: first = charDequeue.removeFront() second = charDequeue.removeRear() if first != second: stillEqual = False return stillEqual
def pal_checker(mystr): """检查字符串是否为回文字符串,即正序等于逆序字符串""" dq = Dequeue() mylist = [i for i in mystr] indicator = True for item in mylist: dq.addRear(item) for i in range(dq.size() // 2): fornt = dq.removeFront() rear = dq.removeRear() if fornt != rear: indicator = False break return indicator
def pal_checker(word): chardequeue = Dequeue() for char in word: chardequeue.add_rear(char) still_equal = True while chardequeue.size() > 1 and still_equal: first = chardequeue.remove_front() last = chardequeue.remove_rear() if first != last: still_equal = False return still_equal