コード例 #1
0
	def set(self,index,element):
		newNode = LinkedListNode(element)
		if(index>0):
			prevNode = self.get(index-1)
		newNode.next = prevNode.next.next
		prevNode.next = newNode
		prevNode.next.next = None
コード例 #2
0
	def insert(self,index,element):
		newNode = LinkedListNode(element)
		if(index==0):
			self.push_front(newNode)
		else:
			prevNode = self.get(index-1)
			newNode.next = prevNode.next
			prevNode.next = newNode

		return newNode
コード例 #3
0
	def insert(self, data):
		""" Insert the data to front list. Returns True if the data was added, False otherwise. """
		curr = Node(data)
		if self.size == 0:
			self.head = curr
			self.size += 1
			return True
		curr.next = self.head
		self.head = curr
		self.size += 1
		return True
コード例 #4
0
	def push_front(self,element):
		newRoot = LinkedListNode(element)
		oldRoot = self.root
		self.root = newRoot
		newRoot.next = oldRoot