def enqueue(self, x): new_node = LinkedList.LLNode(x) if self.is_empty(): self.list.head = new_node # make new node the head if list is empty else: temp = self.list.head while temp.next is not None: temp = temp.next # find the end of the queue temp.next = new_node # place new node at the open space at end of queue self.end += 1
def push(self, x): new_node = LinkedList.LLNode(x) #create new node with given data new_node.next = self.list.head #move old head of list to the next to new node self.list.head = new_node # make new node the head of the list self.top += 1 #increment the index of the top of the stack