当前位置: 首页>>代码示例>>Python>>正文


Python Node.setNext方法代码示例

本文整理汇总了Python中Node.Node.setNext方法的典型用法代码示例。如果您正苦于以下问题:Python Node.setNext方法的具体用法?Python Node.setNext怎么用?Python Node.setNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Node.Node的用法示例。


在下文中一共展示了Node.setNext方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: addAtIndex

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
    def addAtIndex(self, index, data):
        # Continue if index is valid
        if index >= 0 and index <= self.__numberNodes:
            if index == 0:  # Push element to front of list if index is 0
                self.push(data)
            elif index == self.__numberNodes:  # Add element to end of list if index is last element
                self.add(data)
            else:
                # Continue if list is not empty
                if self.__head is not None and self.__tail is not None:
                    addNode = Node(data)
                    currentNode = self.__head.getNext()
                    previousNode = self.__head

                    count = 1
                    while currentNode is not None:  # Traverse list to find element at index
                        # Insert element when index is found
                        if count == index:
                            previousNode.setNext(addNode)
                            addNode.setNext(currentNode)
                            self.__numberNodes = self.__numberNodes + 1
                            break
                        # Prepare for next iteration
                        previousNode = currentNode
                        currentNode = currentNode.getNext()
                        count = count + 1
开发者ID:bpred754,项目名称:AlgorithmsAndDataStructures,代码行数:28,代码来源:LinkedList.py

示例2: push

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
 def push(self, data):
     addNode = Node(data)
     # Set head and tail to new pointer if list is empty
     if self.__head is None:
         self.__head = addNode
         self.__tail = addNode
     else:
         addNode.setNext(self.__head)  # Set new node's next pointer to the current head
         self.__head = addNode  # Set head to new node
     self.__numberNodes = self.__numberNodes + 1
开发者ID:bpred754,项目名称:AlgorithmsAndDataStructures,代码行数:12,代码来源:LinkedList.py

示例3: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
    def add(self, item):
        """
        Adds an item to the start of the list
        :param item: Any object
        :return: Linked list with new object added
        """

        tempNode = Node(item)
        tempNode.setNext(self.head)
        self.head = tempNode
        self.lastElem = tempNode
开发者ID:IggyC,项目名称:DataStructures_Python,代码行数:13,代码来源:LinkedList.py

示例4: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
    def insert(self,item,idx):
        current = self.head
        n = 0
        while n < idx:
            current = current.getNext()
            n += 1

        insertee = Node(item)
        nxt = current.getNext()
        current.setNext(insertee)
        insertee.setNext(nxt)
开发者ID:agiosKatastrof,项目名称:ak_python,代码行数:13,代码来源:UnorderedList.py

示例5: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
 def add(self, data):
     current = self.head
     prev = None
     while not (current is None):
         if current.getData() > data:
             break
         else:
             prev = current
             current = current.getNext()
     temp = Node(data)
     if prev is None:
         temp.setNext(self.head)
         self.head = temp
     else:
         temp.setNext(current)
         prev.setNext(temp)
开发者ID:mbhushan,项目名称:ps-algods-py,代码行数:18,代码来源:OrderedList.py

示例6: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
    def add(self, item):
        current = self.head
        previous = None
        stop = False
        while current is not None and stop is False:
            if current.getData() > item:
                stop = True
            else:
                previous = current
                current = current.getNext()

        temp = Node(item)
        if previous is None:
            temp.setNext(self.head)
            self.head = temp
        else:
            previous.setNext(temp)
            temp.setNext(current)
开发者ID:weezer,项目名称:pythonalgorithmsanddatastructure,代码行数:20,代码来源:OrderedList.py

示例7: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
 def add(self,item):
     ''' this method is different from linked list '''
     current = self.head
     previous = None
     stop = False
     while current != None and not stop:
         if current.getData() > item:
             stop = True
         else:
             previous = current
             current = current.getNext()
     temp = Node(item)
     if previous == None:
         temp.setNext(self.head)
         self.head = temp
     else:
         temp.setNext(current)
         previous.setNext(temp)
开发者ID:ricardo64,项目名称:Over-100-Exercises-Python-and-Algorithms,代码行数:20,代码来源:ordered_list.py

示例8: setUp

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
 def setUp(self):
     self.palindrome = PalindromCheck()
     node1 = Node()
     node2 = Node()
     node3 = Node()
     node4 = Node()
     node5 = Node()
     node6 = Node()
     node1.setValue(1)
     node1.setNext(node2)
     node2.setValue(2)
     node2.setNext(node3)
     node3.setValue(3)
     node3.setNext(node4)
     node4.setValue(3)
     node4.setNext(node5)
     node5.setValue(2)
     node5.setNext(node6)
     node6.setValue(1)
     self.palindrome.setValue(node1)
开发者ID:AssaultKoder95,项目名称:Google,代码行数:22,代码来源:Palindrom.py

示例9: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
    def insert(self, item, index):
        """
        Adds an element at the index
        :param item: Any object
        :param index: An integer
        :return:
        """

        temp = Node(item)
        current = self.head
        count = 1

        if index == count or self.isEmpty():
            self.add(item)
            return
        while count < index:
            current = current.getNext()
            count += 1


        temp.setNext(current.getNext().getNext())
        current.setNext(temp)
        return
开发者ID:IggyC,项目名称:DataStructures_Python,代码行数:25,代码来源:LinkedList.py

示例10: addNode

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
 def addNode(self, item):
     temp = Node(item)
     temp.setNext(self.head)
     self.head = temp
开发者ID:weezer,项目名称:pythonalgorithmsanddatastructure,代码行数:6,代码来源:UnorderedList.py

示例11: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
 def add(self, data):
     temp = Node(data)
     temp.setNext(self.head)
     self.head = temp
开发者ID:mbhushan,项目名称:ps-algods-py,代码行数:6,代码来源:UnorderedList.py

示例12: LinkedList

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setNext [as 别名]
class LinkedList():

    def __init__ (self):
        
        self.firstNode = None

    def append(self, value):
        
        if self.firstNode is None:
            self.firstNode = Node(value)
        else:
            previous_node = self.firstNode

            while True:
                if previous_node.getNext() is None:
                    newNode = Node(value)
                    previous_node.setNext(newNode)
                    break

                previous_node = previous_node.getNext()
            
    def pop(self):
        
        if self.firstNode is None:
            raise IndexError('Out of range')

        elif self.firstNode.getNext() is None:

            lastNode = self.firstNode
            self.firstNode = None

            return lastNode.getValue()

        else:
            lastNode = self.firstNode

            while True:
                
                if lastNode.getNext() is None:
                    currentNode.setNext(None)
                    break

                currentNode = lastNode
                lastNode = lastNode.getNext()

            return lastNode.getValue()

    def prepend(self, value):

        if self.firstNode is None:
            self.firstNode = Node(value)
        else:
            previous_node = self.firstNode
            self.firstNode = Node(value)
            self.firstNode.setNext(previous_node)

    def set(self):
        pass

    def get(self, index):
        
        previous_node = self.firstNode
        
        while True:
            if previous_node is None:
                raise IndexError()
            
            if index == 0:
                return previous_node.getValue()

            index -= 1
            previous_node = previous_node.getNext()


    def length(self):
        return len(self)

    def __str__ (self):

        if self.firstNode is None:
            return '[]'
        
        string = '['
        previous_node = self.firstNode

        while True:
            
            if previous_node.getNext() is None:
                string += str(previous_node)
                break
            
            else:
                string += str(previous_node) + ', '

            previous_node = previous_node.getNext()

        string += ']'

        return string

#.........这里部分代码省略.........
开发者ID:pavelzamyatin,项目名称:algorithms,代码行数:103,代码来源:List.py


注:本文中的Node.Node.setNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。