def append(self, item): current = self.head if current: while current.getNext() is not None: current = current.getNext() current.setNext(Node(item)) else: self.head = Node(item)
def insert(self, pos, item): node = Node(item) if not self.head: self.head = node elif pos == 0: node.next = self.head self.head = node else: previous = None current = self.head current_position = 0 while (current_position < pos) and current.getNext(): previous = current current = current.getNext() current_position += 1 previous.next = node node.next = current return self.head
def enqueue(self, data): new_item = Node(data) current = self.head if current is None: self.head = new_item else: while current.getNext(): current = current.getNext() current.setNext(new_item)
def add(self, item): temp = Node(item) temp.setNext(self.head) self.head = temp