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


Python Node.set_next方法代码示例

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


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

示例1: test_question_three

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
def test_question_three():
	print('\nTesting Question Three\n--------------------')
	
	#Test1
	print("Test 1\n")
	first_node = Node("ann")
	second_node = Node("bob")
	third_node = Node("cat")
	first_node.set_next(second_node)
	second_node.set_next(third_node)
	expected_chain = "ann cat bob None"
	original_chain = ""
	original_chain += str(first_node) + " "
	original_chain += str(first_node.get_next()) + " "
	original_chain += str(first_node.get_next().get_next()) + " "
	original_chain += str(first_node.get_next().get_next().get_next())	
	Asst2.back_to_front_chain(first_node)
	new_chain = ""
	new_chain += str(first_node) + " "
	new_chain += str(first_node.get_next()) + " "
	new_chain += str(first_node.get_next().get_next()) + " "
	new_chain += str(first_node.get_next().get_next().get_next())
	print("Original chain = ", original_chain)
	print("Expected chain = ", expected_chain)
	print("New chain      = ", new_chain)
	display_message(expected_chain == new_chain)
	print()
开发者ID:comradesmith,项目名称:UoA,代码行数:29,代码来源:PaulsTestProgramAsst2.py

示例2: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
    def add(self, val):
        current = self.head
        previous = None
        stop = False
        while current != None and not stop:
            if current.get_data() > val:
                stop = True
            else:
                previous = current
                current = current.get_next()

        temp = Node(val)
        if previous == None:
            temp.set_next(self.head)
            self.head = temp
        else:
            temp.set_next(current)
            previous.set_next(temp)
开发者ID:redcho,项目名称:PythonDataStructures,代码行数:20,代码来源:OrderedList.py

示例3: create_linked_list

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
def create_linked_list():
    A = Node(1)
    B = Node(2)
    C = Node(3)
    D = Node(4)
    E = Node(5)

    A.set_next(B)
    B.set_next(C)
    C.set_next(D)
    D.set_next(E)

    return A
开发者ID:murtzdhulz,项目名称:algorithms_practice,代码行数:15,代码来源:k-to-last.py

示例4: test_build_linked_list

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
def test_build_linked_list():
	test_list = get_test_linked_list()
	new_head = Node("Z")
	new_head.set_next(test_list.head)
	test_list.set_head(new_head)

	cur_node = test_list.head
	assert cur_node.value == "Z"

	cur_node = cur_node.get_next()
	assert cur_node.value == "A"

	cur_node = cur_node.get_next()
	assert cur_node.value == "B"

	cur_node = cur_node.get_next()
	assert cur_node.value == "C"

	cur_node = cur_node.get_next()
	assert cur_node is None
开发者ID:bfortuner,项目名称:boring-stuff,代码行数:22,代码来源:LinkedList.py

示例5: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
 def add(self, key, data):
     new_node = Node(key, data)
     curr = self.__head
     prev = None
     stop = False
     while curr != None and not stop:
         if key < curr.get_key():
             stop = True
         elif key == curr.get_key():
             curr.set_data(data)
             stop = True
         else:
             prev = curr
             curr = curr.get_next()
     new_node.set_next(curr)
     if prev == None:
         self.__head = new_node
     elif prev == new_node:
         new_node.remove(key)
     else:
         prev.set_next(new_node)
     self.__count += 1
开发者ID:Uranium236,项目名称:CS105,代码行数:24,代码来源:OrderedList.py

示例6: test_findIntersection

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
def test_findIntersection():
    ## Create first list
    first1 = Node(3)
    second1 = Node(1)
    third1 = Node(5)
    fourth1 = Node(9)
    common = Node(7)
    sixth1 = Node(2)
    seventh1 = Node(1)

    first1.set_next(second1)
    second1.set_next(third1)
    third1.set_next(fourth1)
    fourth1.set_next(common)
    common.set_next(sixth1)
    sixth1.set_next(seventh1)

    ## Create second list
    first2 = Node(4)
    second2 = Node(6)

    first2.set_next(second2)
    second2.set_next(common)

    ## Check for intersection
    intersection = findIntersection(first1, first2)

    assert(intersection is not None)
    assert(intersection.get_key() == 7)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:31,代码来源:findIntersection_test.py

示例7: add

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

示例8: insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
	def insert(self, key):
		node = Node(key)
		node.set_next(self.head)
		if self.head is not None:
			self.head.set_prev(node)
		self.head = node
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:8,代码来源:LinkedList.py

示例9: add

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
	def add(self,item):
		newNode = Node(item)
		newNode.set_next(self.head)
		self.head = newNode
		self.length += 1
		return
开发者ID:hshidara,项目名称:Data-Structures,代码行数:8,代码来源:LinkedList.py

示例10: test_question_three

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import set_next [as 别名]
def test_question_three():
    print('\n====================\n Testing Question 3\n====================')

    first_node = Node('ann')
    second_node = Node('bob')
    third_node = Node('cat')
    first_node.set_next(second_node)
    second_node.set_next(third_node)
    Asst2.back_to_front_chain(first_node)
    
    print('Test 1\n', '  Expected = ann cat bob None', '\n   Got      =', end = ' ')

    print(first_node.get_data(), end = ' ')
    print(first_node.get_next().get_data(), end = ' ')
    print(first_node.get_next().get_next().get_data(), end = ' ')
    print(first_node.get_next().get_next().get_next())

    first_node = Node(1)
    second_node = Node(2)
    third_node = Node(3)
    fourth_node = Node(4)
    fifth_node = Node(5)
    first_node.set_next(second_node)
    second_node.set_next(third_node)
    third_node.set_next(fourth_node)
    fourth_node.set_next(fifth_node)

    Asst2.back_to_front_chain(first_node)
    
    print('Test 2\n', '  Expected = 1 5 2 3 4 None', '\n   Got      =', end = ' ')

    print(first_node.get_data(), end = ' ')
    print(first_node.get_next().get_data(), end = ' ')
    print(first_node.get_next().get_next().get_data(), end = ' ')    
    print(first_node.get_next().get_next().get_next().get_data(), end = ' ')
    print(first_node.get_next().get_next().get_next().get_next().get_data(), end = ' ')
    print(first_node.get_next().get_next().get_next().get_next().get_next())

    first_node = Node(1)
    second_node = Node(2)

    first_node.set_next(second_node)

    Asst2.back_to_front_chain(first_node)
    
    print('Test 3\n', '  Expected = 1 2 None', '\n   Got      =', end = ' ')

    print(first_node.get_data(), end = ' ')
    print(first_node.get_next().get_data(), end = ' ')
    print(first_node.get_next().get_next())
开发者ID:comradesmith,项目名称:UoA,代码行数:52,代码来源:ClarissaTest.py

示例11: add_node

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


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