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


Python Node.next方法代码示例

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


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

示例1: push

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
	def push(self, value):
		"""
		Add value to top of Stack
		"""
		new_node = Node(value)
		new_node.next = self.head
		self.head = new_node
开发者ID:bfortuner,项目名称:boring-stuff,代码行数:9,代码来源:Stack.py

示例2: push

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
 def push(self, value):
     new_node = Node(value, None, None)
     new_node.previous = self.end.previous
     new_node.next = self.end
     self.end.previous.next = new_node
     self.end.previous = new_node
     self.size += 1
开发者ID:xym4,项目名称:PracticeDS,代码行数:9,代码来源:Stack.py

示例3: insertItem

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
 def insertItem(self, value, position):
     node = Node(value)
     if self.count > position:
         if position == 0:
             node.next = self.head
             self.head.prev = node
             self.head = node
         else:
             currentNode = self.head
             for i in range(0, position):
                 currentNode = currentNode.next
             node.next = currentNode
             node.prev = currentNode.prev
             currentNode.prev.next = node
             currentNode.prev = node
         self.count += 1
开发者ID:erginbilgin,项目名称:PythonDoublyLinkedList,代码行数:18,代码来源:MyLinkedList.py

示例4: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
	def add(self,data):
		newNode=Node(data,None,None)
		frontNode=self._header
		backNode=frontNode.next
		frontNode.next=newNode
		backNode.prev=newNode
		newNode.prev=frontNode
		newNode.next=backNode
开发者ID:eewilliac,项目名称:PythonLinkedList,代码行数:10,代码来源:DoublyLinkedList.py

示例5: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
 def add(self, ndata):
     node = Node(ndata)
     if self.head is None:
         self.head = node
     else:
         node.next = self.head
         self.head = node
     self.N += 1
开发者ID:mbhushan,项目名称:ps-algods-py,代码行数:10,代码来源:LinkedList.py

示例6: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
 def add(self, data):
     newNode = Node(data, None, None)
     if self.isEmpty():
         self.head = newNode
         self.end = newNode
     else:
         self.head.previous = newNode
         newNode.next = self.head
         self.head = newNode
开发者ID:bry012,项目名称:DataStructures,代码行数:11,代码来源:DLL.py

示例7: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
    def insert(self, key, pos=0):
        if pos < 0 or pos > self.length:
            raise ValueError

        new_node = Node(key)

        if pos == 0:
            new_node.next = self.HEAD.next
            self.HEAD.next = new_node
        else:
            curr_node = self.HEAD.next
            prev_node = self.HEAD
            for i in xrange(pos):
                prev_node = curr_node
                curr_node = curr_node.next
            new_node.next = curr_node
            prev_node.next = new_node
        self.length += 1
开发者ID:karandevgan,项目名称:Algorithms,代码行数:20,代码来源:SinglyLinkedList.py

示例8: build_list

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
def build_list(nodes_dict, file_content):
    # should be pointing to the start of the list
    nodes_as_linked_list = None

    for line in file_content:
        tokens = line.split()
        node_a_name = ""
        node_b_name = ""
        switch = 0
        before = True
        for string in tokens:
            if string == "after":
                before = False
            elif string == "comes":
                switch = 1
            elif not string == "before":
                if switch == 0:
                    node_a_name += string
                else:
                    node_b_name += string

        # after the for loop, node_a_name is the name of the first city
        # node_b_name is the name of hte second city
        # if before is True, then node_a_name comes before node_b_name
        # else, node_a_name comes after node_b_name

        if not node_a_name in nodes_dict:
            nodes_dict[node_a_name] = Node(node_a_name)
        if not node_b_name in nodes_dict:
            nodes_dict[node_b_name] = Node(node_b_name)

        if not modify_nodes(nodes_dict, node_a_name, node_b_name, before):
            return None

        if nodes_as_linked_list is None:
            nodes_as_linked_list = nodes_dict[node_a_name]
            if before:
                # set head to node A and set node A's next to point to B
                nodes_as_linked_list.prev = None
                nodes_as_linked_list.next = nodes_dict[node_b_name]
                nodes_dict[node_b_name].prev = nodes_as_linked_list
                nodes_dict[node_b_name].next = None
            else:
                # set head to node B and set node B's next to point to A
                nodes_as_linked_list.prev = nodes_dict[node_b_name]
                nodes_as_linked_list.next = None
                nodes_as_linked_list = nodes_as_linked_list.prev
                nodes_as_linked_list.next = nodes_dict[node_a_name]
                nodes_as_linked_list.prev = None
        else:
            if before:
                nodes_as_linked_list = modify_linked_list(node_a_name, node_b_name, nodes_dict, nodes_as_linked_list)
            else:
                nodes_as_linked_list = modify_linked_list(node_b_name, node_a_name, nodes_dict, nodes_as_linked_list)

    return nodes_as_linked_list
开发者ID:jojojames,项目名称:Python,代码行数:58,代码来源:puzzle_3.py

示例9: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
 def insert(self, value):
     new_node = Node(value, None, None)
     cur = self.head
     while cur.next != self.end:
         cur = cur.next
     cur.next = new_node
     new_node.previous = cur
     new_node.next = self.end
     self.end.previous = new_node
     self.size+=1
开发者ID:xym4,项目名称:PracticeDS,代码行数:12,代码来源:LinkedList.py

示例10: append

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
    def append(self, data):
        new_node = Node(data, None, None)

        if self.head == None:
            self.head = self.tail = new_node
        else:
            new_node.prev = self.tail
            new_node.next = None
            self.tail.next = new_node
            self.tail = new_node
开发者ID:Nyranith,项目名称:Overload-Factory-IS-105,代码行数:12,代码来源:buffer.py

示例11: insertFirst

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
 def insertFirst(data):
     new = Node(data);
     if(self.isEmpty()):
         head = new;
         head.next = head;   #loop back to first element
         end = head;
     else:
         new.next = head;
         end.next = new;
         head = new;
开发者ID:Narendraravaria,项目名称:Python-Solutions,代码行数:12,代码来源:CircularLinkedList_old.py

示例12: add_at_start

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
    def add_at_start(self, value):
        new_node = Node(value, None, None)

        if(self.head == None):
            self.head = new_node
        else:
            new_node.next = self.head

            self.head.prev = new_node

            self.head = new_node
开发者ID:Nyranith,项目名称:Overload-Factory-IS-105,代码行数:13,代码来源:buffer.py

示例13: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
 def insert(self, cargo):
   node = Node(cargo)
   node.next = None
   if self.head == None:
     
     self.head = node
   else:
     
     last = self.head
     while last.next: last = last.next
     
     last.next = node
   self.length = self.length + 1
开发者ID:hebertom,项目名称:modelagemSemaforo,代码行数:15,代码来源:Queue.py

示例14: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
    def insert(self, data, index):
        """ insert data at given index in the linked list"""
        if not isinstance(index, int):
            print ("Index should be of type Integer, str() passed")
            return False
        if index < 0 or index > self.size():
            print ("Bad Index Range!")
            return False
        curr = self.head
        prev = None
        count = 0
        node = Node(data)

        if index == self.size():
            print ("Inserting at tail")
            self.tail.next = node
            self.tail = self.tail.next
            self.N += 1
            return True

        while curr is not None:
            if count == index:
                break
            prev = curr
            curr = curr.next
            count += 1
        if prev is None:
            print ("Inserting at head")
            node.next = self.head
            self.head = node
        else:
            print ("Inserting in between: ", count)
            node.next = curr
            prev.next = node
        self.N += 1
        return True
开发者ID:mbhushan,项目名称:ps-algods-py,代码行数:38,代码来源:SLList.py

示例15: add_before

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import next [as 别名]
    def add_before(self, before_value, node_value):
        current_node = self.head
        new_node = Node(node_value, None, None)


        while current_node is not None:
            if current_node.data == before_value:
                if current_node.prev == None:
                    self.add_at_start(node_value)
                    #new_node.next = self.head
                    #self.head.prev = new_node
                    #self.head = new_node
                else:
                    new_node.prev = current_node.prev
                    new_node.next = current_node

                    current_node.prev = new_node

                break

            current_node = current_node.next
开发者ID:Nyranith,项目名称:Overload-Factory-IS-105,代码行数:23,代码来源:buffer.py


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