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


Python LinkedList.swap方法代码示例

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


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

示例1: test_swap_only_items_from_list

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import swap [as 别名]
 def test_swap_only_items_from_list(self):
     ll = LinkedList()
     ll2 = LinkedList()
     item1 = ll.add_to_front(5151, 91951)
     item2 = ll2.add_to_front(58888888, 851)
     with pytest.raises(Exception):
         ll.swap(item1, item2)
开发者ID:teroqim,项目名称:linkedlist,代码行数:9,代码来源:test_linkedlist.py

示例2: test_swap_preserves_length

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import swap [as 别名]
 def test_swap_preserves_length(self):
     ll = LinkedList()
     item1 = ll.add_to_front(5151, 91951)
     assert ll.length == 1
     item2 = ll.add_to_front(235151, 91951)
     assert ll.length == 2
     ll.swap(item1, item2)
     assert ll.length == 2
开发者ID:teroqim,项目名称:linkedlist,代码行数:10,代码来源:test_linkedlist.py

示例3: test_swap_same_no_effect

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import swap [as 别名]
 def test_swap_same_no_effect(self):
     ll = LinkedList()
     item1 = ll.add_to_back(123, 91284)
     item2 = ll.add_to_back(51515, 192)
     assert ll.front == item1
     assert ll.back == item2
     assert ll.length == 2
     ll.swap(item1, item1)
     assert ll.front == item1
     assert ll.back == item2
     assert ll.length == 2
开发者ID:teroqim,项目名称:linkedlist,代码行数:13,代码来源:test_linkedlist.py

示例4: test_swap_non_edge_items

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import swap [as 别名]
 def test_swap_non_edge_items(self):
     ll = LinkedList()
     item1 = ll.add_to_back(5151, 91951)
     item2 = ll.add_to_back(235151, 91951)
     item3 = ll.add_to_back(512351, 91951)
     item4 = ll.add_to_back(510951, 91951)
     item5 = ll.add_to_back(51747451, 91951)
     ll.swap(item2, item4)
     assert item1.next.key == item4.key
     assert item4.next == item3
     assert item3.next == item2
     assert item2.next == item5
     assert item5.prev == item2
     assert item2.prev == item3
     assert item3.prev == item4
     assert item4.prev == item1
开发者ID:teroqim,项目名称:linkedlist,代码行数:18,代码来源:test_linkedlist.py

示例5: test_swap_None_no_switch

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import swap [as 别名]
 def test_swap_None_no_switch(self):
     ll = LinkedList()
     with pytest.raises(Exception):
         ll.swap(None, None)
     assert ll.length == 0
     item1 = ll.add_to_back(123, 12141)
     with pytest.raises(Exception):
         ll.swap(item1, None)
     assert ll.length == 1
     assert ll.front == item1
     with pytest.raises(Exception):
         ll.swap(None, item1)
     assert ll.length == 1
     assert ll.front == item1
开发者ID:teroqim,项目名称:linkedlist,代码行数:16,代码来源:test_linkedlist.py

示例6: test_swap_back

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import swap [as 别名]
 def test_swap_back(self):
     ll = LinkedList()
     item1 = ll.add_to_front(1414, 1414)
     item2 = ll.add_to_back(431, 4321)
     ll.swap(item1, item2)
     ll.back == item1
开发者ID:teroqim,项目名称:linkedlist,代码行数:8,代码来源:test_linkedlist.py


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