Exemple #1
0
    def test_remove(self):
        rb = RingBuffer(4)
        rs = RingStack(4)
        rq = RingQueue(4)
        ls = ListStack(4)
        lq = ListQueue(4)
        for name in TestRingBufferDS.names:
            rb.insert_keep_old(name)
            rs.insert(name)
            rq.insert(name)
            ls.insert(name)
            lq.insert(name)

        print("Before remove: ")
        print("RingBuffer:", rb)
        print("RingStack:", rs)
        print("RingQueue:", rq)
        print("ListStack:", ls)
        print("ListQueue:", lq)

        for i in range(2):
            rs.remove()
            rq.remove()
            ls.remove()
            lq.remove()

        print("After remove: ")
        print("RingBuffer:", rb)
        print("RingStack:", rs)
        print("RingQueue:", rq)
        print("ListStack:", ls)
        print("ListQueue:", lq)
Exemple #2
0
    def test_insert(self):
        rb = RingBuffer(4)
        rs = RingStack(4)
        rq = RingQueue(4)
        ls = ListStack(4)
        lq = ListQueue(4)
        for name in TestRingBufferDS.names:
            rb.insert_keep_old(name)
            rs.insert(name)
            rq.insert(name)
            ls.insert(name)
            lq.insert(name)

        print("RingBuffer:", rb)
        print("RingStack:", rs)
        print("RingQueue:", rq)
        print("ListStack:", ls)
        print("ListQueue:", lq)
print("Reseting the Queue with size 0")
list1 = Queue(0)
print("Now trying to add 1")
list1.enqueue(1)
print("Now trying to print Queue")
list1.__str__()
print("Now trying to dequeqe")
list1.dequeue()

print("-------------------")
print("Test case of ListStack")
sizeOfLS = int(input("Enter size of ListStack"))
a = ListStack(sizeOfLS)
print("Adding 1")
a.insert(1)
print('peek ', a.peek(), 'currently contains', a)
print("Adding 2")
a.insert(2)
print("Adding 3")
a.insert(3)
print("ListStack as of now ", a)
print("Adding 4.")
a.insert(4)
print("ListStack as of now ", a)
print("capacity of ListStack is", a.capacity())
print("Removing ", a.peek())
a.remove()
print(a)

print("------------------")
Exemple #4
0
def main():
    print('\n\nCreating empty ListStack named "a" of size 4')
    a = ListStack(4)
    print('Creating empty ListQueue named "b" of size 4')
    b = ListQueue(4)
    print('Creating empty Stack named "c" of size 4')
    c = Stack(4)
    print('Creating empty Queue named "d" of size 4')
    d = Queue(4)
    print("")

    print("PEEKING ON AN (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE")
    print('peek on a', a.peek(), 'currently contains', a.__str__())
    print('peek on b', b.peek(), 'currently contains', b.__str__())
    print('peek on c', c.peek(), 'currently contains', c.__str__())
    print('peek on d', d.peek(), 'currently contains', d.__str__())
    print("")

    print(
        " ----------- INSERTING VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for val in range(6):
        print('inserting', val,
              'into both a(ListStack), b(ListQueue), c(Stack), d(Queue)\n')
        print("")
        a.insert(val)
        b.insert(val)
        c.push(val)
        d.enqueue(val)
        print('peek on a', a.peek(), 'currently contains', a.__str__())
        print('peek on b', b.peek(), 'currently contains', b.__str__())
        print('peek on c', c.peek(), 'currently contains', c.__str__())
        print('peek on d', d.peek(), 'currently contains', d.__str__())

    print("")
    print(
        " ----------- REMOVING VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for i in range(4):
        print('Removing', i,
              'into both a(ListStack), b(ListQueue), c(Stack), d(Queue)')
        print('Before removing', a.peek(), 'from a', a.__str__())
        a.remove()
        print('peek on a', a.peek(), 'after removing', a.__str__())
        print("")

        print('Before removing', b.peek(), 'from b', b.__str__())
        b.remove()
        print('peek on a', a.peek(), 'after removing', b.__str__())
        print("")

        print('Before removing', c.peek(), 'from c', c.__str__())
        c.pop()
        print('peek on c', c.peek(), 'after removing', c.__str__())
        print("")

        print('Before removing', c.peek(), 'from d', d.__str__())
        d.dequeue()
        print('peek on d', c.peek(), 'after removing', d.__str__())
        print("")

    l = [10, 2, 23, 35, 76]
    print(
        " ----------- INSERTING USER DEFINED VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for val in l:
        print('inserting', val,
              'into both a and b and c which is user defined')
        a.insert(val)
        b.insert(val)
        c.push(val)
        d.enqueue(val)
        print('peek on a', a.peek(), 'currently contains', a.__str__())
        print('peek on b', a.peek(), 'currently contains', b.__str__())
        print('peek on b', c.peek(), 'currently contains', c.__str__())
        print('peek on d', d.peek(), 'currently contains', d.__str__())
        print("")

    print("")
    print(
        " ----------- REMOVING USER DEFINED VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for i in l:
        print('Removing', i,
              'into both a(ListStack), b(ListQueue), c(Stack), d(Queue)')
        print('Before removing', a.peek(), 'from a', a.__str__())
        a.remove()
        print('peek on a', a.peek(), 'after removing', a.__str__())
        print("")

        print('Before removing', b.peek(), 'from b', b.__str__())
        b.remove()
        print('peek on a', a.peek(), 'after removing', b.__str__())
        print("")

        print('Before removing', c.peek(), 'from c', c.__str__())
        c.pop()
        print('peek on c', c.peek(), 'after removing', c.__str__())
        print("")

        print('Before removing', c.peek(), 'from d', d.__str__())
        d.dequeue()
        print('peek on d', c.peek(), 'after removing', d.__str__())
        print("")