Пример #1
0
def addFront(list, head, val):
    newNode = Node(val)
    if head:
        newNode.next = head

    list.setHeadNode(newNode)
    list.recalculateLength()
    return list.getHeadNode()
Пример #2
0
def addBack(list, head, val):
    newNode = Node(val)
    if not head:
        list.setHeadNode(newNode)
    else:
        while head.next:
            head = head.next
        head.next = newNode
    list.recalculateTail()
    list.recalculateLength()
Пример #3
0
    def add(self, data):
        newNode = Node(data)
        if not self.__tail:
            self.__head = newNode
            self.__tail = newNode
        else:
            self.__tail.next = newNode
            self.__tail = newNode

        self.__length += 1
	def createNode(self, val):
		node = Node()
		node.setVal(val)
		return node
	def createNode(self, val):
		node = Node()
		node.setVal(val)
		node.setNext(None)
		return node
Пример #6
0
 def push(self, ele):
     temp = ListNode()
     temp.setVal(ele)
     temp.setNext(self.top)
     self.top = temp