Exemplo n.º 1
0
 def test_remove_deque(self):
     test_deque = deque.Deque()
     test_deque.add_front("cat")
     test_deque.add_front("dog")
     test_deque.add_front(1)
     self.assertEqual(test_deque.remove_rear(), "cat")
     self.assertEqual(test_deque.remove_front(), 1)
Exemplo n.º 2
0
 def test_add_deque(self):
     test_deque = deque.Deque()
     test_deque.add_front("cat")
     self.assertEqual(test_deque.size(), 1)
     test_deque.add_front("dog")
     self.assertEqual(test_deque.size(), 2)
     test_deque.add_front(1)
     self.assertEqual(test_deque.size(), 3)
Exemplo n.º 3
0
def isPalindrome(string):
    """check if the given string is a palindrome
        return: boolean
    """

    d = deque.Deque()
    for char in string:
        d.addFront(char)

    times = d.size() // 2
    for _ in range(times):
        if not d.removeFront() == d.removeRear():
            return False
    return True
Exemplo n.º 4
0
def palchecker(astring):

    char = deque.Deque()

    for ch in astring:
        char.addrear(ch)

    print(char.items)

    stillequal = True

    while char.size() > 1 and stillequal:
        first = char.removefront()
        print("first-->", first)
        last = char.removerear()
        print("last-->", last)
        if first != last:
            stillequal = False

    return stillequal
Exemplo n.º 5
0
 def __init__(self, capacity=10):
     self.lru_deque = deque.Deque()
     self.MAX_CAPACITY = capacity
     self.current_capacity = 0
     self.node_map = {}
Exemplo n.º 6
0
 def my_deque(self):
     return deque.Deque(6)
Exemplo n.º 7
0
 def test_create_deque(self):
     test_deque = deque.Deque()
     self.assertEqual(test_deque.is_empty(), True)
     self.assertEqual(test_deque.size(), 0)