本文整理汇总了Python中linkedlist.LinkedList.reverse方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.reverse方法的具体用法?Python LinkedList.reverse怎么用?Python LinkedList.reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linkedlist.LinkedList
的用法示例。
在下文中一共展示了LinkedList.reverse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reverse_single
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import reverse [as 别名]
def test_reverse_single(self):
ll = LinkedList(358)
self.assertEqual(358, ll.peek())
self.assertEqual(1, len(ll))
ll.reverse()
self.assertEqual(358, ll.peek())
self.assertEqual(1, len(ll))
示例2: test_reverse
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import reverse [as 别名]
def test_reverse(self):
ll = LinkedList(7)
ll.append(8)
ll.append(9)
self.assertEqual(3, len(ll))
self.assertEqual(7, ll.peek())
self.assertEqual("7->8->9", str(ll))
ll.reverse()
self.assertEqual("9->8->7", str(ll))
self.assertEqual(9, ll.peek())
示例3: test_reverse_double
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import reverse [as 别名]
def test_reverse_double(self):
ll = LinkedList(45)
ll.append(46)
self.assertEqual(2, len(ll))
self.assertEqual(45, ll.peek())
self.assertEqual("45->46", str(ll))
ll.reverse()
self.assertEqual(2, len(ll))
self.assertEqual(46, ll.peek())
self.assertEqual("46->45", str(ll))
示例4: TestLinkedListReversal
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import reverse [as 别名]
class TestLinkedListReversal(unittest.TestCase):
def setUp(self):
self.testelements = [5, 3, 6, 7, 8, 10, 6]
self.expectedrev = [6, 10, 8, 7, 6, 3, 5]
self.linkedlist = LinkedList()
for e in self.testelements:
self.linkedlist.append(e)
def test_reversal(self):
self.linkedlist.reverse()
rev = [x for x in self.linkedlist]
self.assertItemsEqual(self.expectedrev, rev)
示例5: test_reverse_empty
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import reverse [as 别名]
def test_reverse_empty(self):
ll = LinkedList()
self.assertTrue(ll.isEmpty())
ll.reverse()
self.assertTrue(ll.isEmpty())
示例6: reverse
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import reverse [as 别名]
# cool implementation of reverse with
def reverse(self, head, k):
current = head
nextNode = None
prev = None
count =0
while current is not None and count<k:
nextNode = current.next
current.next = prev
prev = current
current = nextNode
count+=1
if nextNode is not None:
head.next = self.reverse(nextNode,k)
return prev
llist1 = LinkedList()
llist1.head = Node(2)
llist1.insert(4)
llist1.insert(7)
llist1.insert(8)
llist1.insert(12)
llist1.insert(20)
llist1.printList()
llist1.head = llist1.reverse(llist1.head,3)
llist1.printList()