Deque in Python

Deque

class Queue():
    '''Queue'''
    def __init__(self):
        self.__list = []

    def enqueue(self, item):
        '''Add an element to the queue'''
        self.__list.append(item)

    def dequeue(self):
        '''Delete an element from the queue header'''
        return self.__list.pop(0)

    def is_empty(self):
        '''Determine whether queue is empty'''
        return self.__list == []

    def size(self):
        '''Returns the number of elements in the queue'''
        return len(self.__list)

def main():
    q1 = Queue()
    q1.enqueue(1)
    q1.enqueue(2)
    q1.enqueue(3)
    q1.enqueue(5)
    print(q1.dequeue())
    print(q1.dequeue())
    print(q1.dequeue())
    print(q1.dequeue())

if __name__ == '__main__':
    main()


---------------results of enforcement----------
2
1
4
3

-----------------------------------------------
展开阅读全文

没有更多推荐了,返回首页