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


Python Node.next_node方法代码示例

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


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

示例1: insertAtStart

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next_node [as 别名]
 def insertAtStart(self, data):
     self.counter += 1
     new_node = Node(data)
     if not self.head:
         self.head = new_node
     else:
         new_node.next_node = self.head
         self.head = new_node
开发者ID:harihpr,项目名称:Data-structures-and-Algorithms,代码行数:10,代码来源:LinkedList.py

示例2: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next_node [as 别名]
    def insert(self, value):
        node = Node(value)

        # If the linked list is empty, make this the head node
        if self.head is None:
            self.head = node
            # Otherwise, insert the node into the sorted linked list
        else:
            curr_node = self.head
            b_node_not_added = True
            while b_node_not_added:
                result = self.comparator(node.value, curr_node.value)

                # Store the next and previous node for readability
                prev = curr_node.prev_node
                next = curr_node.next_node

                # If the current node is greater, then insert this node into its spot
                if result < 0:
                    # If the curr_node was the head, replace it with this node
                    if self.head == curr_node:
                        self.head = node
                        # Otherwise, it has a previous node so hook it up to this node
                    else:
                        node.prev_node = prev
                        prev.next_node = node

                        # Hook the current node up to this node
                    node.next_node = curr_node
                    curr_node.prev_node = node

                    b_node_not_added = False
                    # Otherwise, continue traversing
                else:
                    # If we haven't reached the end of the list, keep traversing
                    if next is not None:
                        curr_node = next
                        # Otherwise, append this node
                    else:
                        curr_node.next_node = node
                        node.prev_node = curr_node

                        b_node_not_added = False
开发者ID:hspearman,项目名称:LinkedList,代码行数:45,代码来源:LinkedList.py


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