本文整理汇总了Python中LinkedList.LinkedList.delete方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.delete方法的具体用法?Python LinkedList.delete怎么用?Python LinkedList.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete(self):
x = LinkedList([1,2,3,4,5])
val1 = x.delete(0) # 1st element
val2 = x.delete(-1) # last element
self.assertEqual(val1, 1)
self.assertEqual(val2, 5)
self.assertEqual(list(x), [2,3,4])
示例2: test_delete_head
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete_head():
l_list = LinkedList()
l_list.insert("Batman")
l_list.insert("Superman")
assert l_list.head.get_key() == "Superman"
l_list.delete("Superman")
assert l_list.head.get_key() == "Batman"
示例3: test_delete_value_not_in_list
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete_value_not_in_list():
l_list = LinkedList()
l_list.insert("Jacob")
l_list.insert("Pallymay")
l_list.insert("Rasmus")
with pytest.raises(ValueError):
l_list.delete("Sunny")
示例4: test_size
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_size():
l_list = LinkedList()
assert l_list.size() == 0
l_list.insert("Batman")
l_list.insert("Superman")
assert l_list.size() == 2
l_list.delete("Superman")
assert l_list.size() == 1
示例5: test_deleteNone
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_deleteNone(self):
l = LinkedList(1)
l.add(2)
l.add(3)
l.delete(5)
self.assertEquals(l.val, 1)
self.assertEquals(l.next.val, 2)
self.assertEquals(l.next.next.val, 3)
示例6: test_delete_next_reassignment
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete_next_reassignment():
l_list = LinkedList()
l_list.insert("Jacob")
l_list.insert("Cid")
l_list.insert("Pallymay")
l_list.insert("Rasmus")
l_list.delete("Pallymay")
l_list.delete("Cid")
assert l_list.head.next_node.get_data() == "Jacob"
示例7: test_delete
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete():
l_list = LinkedList()
l_list.insert("Jacob")
l_list.insert("Pallymay")
l_list.insert("Rasmus")
l_list.delete("Rasmus")
assert l_list.head.get_data() == "Pallymay"
l_list.delete("Jacob")
assert l_list.head.get_next() is None
示例8: test_delete
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete():
l_list = LinkedList()
l_list.insert("Batman")
l_list.insert("Superman")
l_list.insert("Wonder Woman")
l_list.delete("Superman")
assert l_list.head.get_next().get_key() == "Batman"
l_list.delete("Batman")
assert l_list.head.get_key() == "Wonder Woman"
示例9: delete
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def delete(self, n):
if self.size > 0:
result = LinkedList.delete(self, n)
if result is not None:
self.size -= 1
return result
return None
示例10: LinkedListTest
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
class LinkedListTest(unittest.TestCase):
def setUp(self):
self.default_list = LinkedList()
self.default_list.insert('a')
self.default_list.insert('b')
self.default_list.insert('c')
self.default_list.insert('d')
def test_insert(self):
self.default_list.insert('z')
self.assertEqual(self.default_list.head.get_data(), 'z')
self.assertEqual(self.default_list.head.get_next().get_data(), 'd')
def test_get_next(self):
self.assertEqual(self.default_list.head.get_next().get_data(), 'c')
def test_search(self):
# search head
self.assertEqual(self.default_list.search('d'), self.default_list.head)
# normal search
self.assertEqual(self.default_list.search('c'), self.default_list.head.get_next())
# search value not in list
self.assertEqual(self.default_list.search('e'), None)
def test_delete_head(self):
self.default_list.delete('d')
self.assertEqual(self.default_list.head.get_data(), 'c')
self.assertEqual(self.default_list.size(), 3)
def test_delete_tail(self):
self.default_list.delete('a')
self.assertEqual(self.default_list.size(), 3)
def test_delete_not_exist(self):
self.assertEqual(self.default_list.delete('e'), None)
示例11: __init__
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
class Stack:
def __init__(self):
self.content = LinkedList()
def push(self, x):
self.content.insert(0, x)
def pop(self):
return self.content.delete(0)
def top(self):
return self.content[0]
def isEmpty(self):
return self.content.isEmpty()
示例12: LinkedList
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
print "After making same size..."
print "== list1 =="
list1.printlist()
print "== list2 =="
list2.printlist()
print "lets add two linked lists..."
#create new linked list to store results
res = LinkedList()
sum = 0
carry = 0
for i in range(0,list1.size()):
sum = list1.last().get_data() + list2.last().get_data() + carry
if sum >= 10:
res.insert(sum-10)
carry = 1
else:
res.insert(sum)
carry = 0
list1.delete(list1.last().get_data())
list2.delete(list2.last().get_data())
if carry == 1:
res.insert(1)
res.printlist()
示例13: test_delete_empty_list
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete_empty_list():
l_list = LinkedList()
with pytest.raises(ValueError):
l_list.delete("Sunny")
示例14: test_delete_value_not_in_list
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_delete_value_not_in_list():
l_list = LinkedList()
l_list.insert("Batman")
l_list.insert("Superman")
with pytest.raises(ValueError):
l_list.delete("Flash")
示例15: test_deleteRoot
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import delete [as 别名]
def test_deleteRoot(self):
l = LinkedList(5)
self.assertIsNone(l.delete(5))