def dequeue(self)"""remove and return the first element of the queue ( fiforaise empty exception if the queue is empty ""if self is empty)raise emptyqueue is empty answer self head element self head self head next self size - special case as queue is empty if self is empty)removed head had been the tail self tail none return answer def enqueue(selfe)"""add an element to the back of queue ""node will be new tail node newest self node(enoneif self is empty)special casepreviously empty self head newest elseself tail next newest update reference to tail node self tail newest self size + code fragment implementation of queue adt using singly linked list (continued from code fragment many aspects of our implementation are similar to that of the linkedstack classsuch as the definition of the nested node class our implementation of dequeue for linkedqueue is similar to that of pop for linkedstackas both remove the head of the linked list howeverthere is subtle difference because our queue must accurately maintain the tail reference (no such variable was maintained for our stackin generalan operation at the head has no effect on the tailbut when dequeue is invoked on queue with one elementwe are simultaneously removing the tail of the list we therefore set self tail to none for consistency there is similar complication in our implementation of enqueue the newest node always becomes the new tail yet distinction is made depending on whether that new node is the only node in the list in that caseit also becomes the new headotherwise the new node must be linked immediately after the existing tail node in terms of performancethe linkedqueue is similar to the linkedstack in that all operations run in worst-case constant timeand the space usage is linear in the current number of elements