def insertFirst(self, data): newNode = Node(data) if not self.head: self.head = newNode else: newNode.nextNode = self.head self.head = newNode
def insertStart(self, data): self.counter += 1 newNode = Node(data) if not self.head: self.head = newNode else: newNode.nextNode = self.head self.head = newNode
def insertStart(self, data): self.counter += 1; newNode = Node(data); if not self.head: self.head = newNode; else: newNode.nextNode = self.head; self.head = newNode;
class LinkedList(object); def __init__(self): self.head = None; self.counter = 0; #constant time def insertStart(self, data); self.counter += 1; newNode = Node(data); if not self.head(data); self.head = newNode; else: newNode.nextNode = self.head; self.head = newNode; # constant time def size(self): return self.counter #insert at the end linear time def insertEnd(self, data): newNode = Node(data); actualNode = self.head; while actualNode.nextNode is not None: actualNode = actualNode.newNode; actualNode.nextNode = newNode;