Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
#dequeue-test-cases
#Rebecca Brunner
#29 August 2018
#Test dequeue class structure and methods

from random import *
from dequeue import Dequeue

#Create deqeueue
d1 = Dequeue()
for i in range(5):
    d1.pushBack(randint(1, 5))
print("Dequeue 1 is: ", d1.items)
d2 = Dequeue()
for i in range(5):
    d2.pushBack(randint(1, 5))
print("Dequeue 2 is: ", d2.items)

d1.insertion_sort()
print("Dequeue 1, sorted with an insertion sort: ", d1.items)
d2.merge_sort()
print("Dequeue 2, sorted with a merge sort:", d2.items)

if (d1.binary_search(4)) != None:
    print("Searching for 4 in d1 with a binary search, 4 is in position ",
          d1.binary_search(4))
else:
    print("Searching for 4 in d1 with a binary search, 4 was not found.")

if (d2.binary_search(4)) != None:
    print("Searching for 4 in d2 with a binary search, 4 is in position ",