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


Python LinkedList.delete方法代码示例

本文整理汇总了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])
开发者ID:xpspectre,项目名称:cell-image,代码行数:9,代码来源:test_LinkedList.py

示例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"
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:9,代码来源:LinkedList_test.py

示例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")
开发者ID:pombredanne,项目名称:CrackCode,代码行数:9,代码来源:TestLinkedList.py

示例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
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:10,代码来源:LinkedList_test.py

示例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)
开发者ID:jackchi,项目名称:interview-prep,代码行数:10,代码来源:test_linkedList.py

示例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"
开发者ID:pombredanne,项目名称:CrackCode,代码行数:11,代码来源:TestLinkedList.py

示例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
开发者ID:pombredanne,项目名称:CrackCode,代码行数:11,代码来源:TestLinkedList.py

示例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"
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:11,代码来源:LinkedList_test.py

示例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
开发者ID:ramda-phi,项目名称:PyPrac,代码行数:9,代码来源:FixedList.py

示例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)
开发者ID:ZachLiuGIS,项目名称:Algorithm-Enthusiasts,代码行数:38,代码来源:test_LinkedList.py

示例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()
开发者ID:ramda-phi,项目名称:PyPrac,代码行数:17,代码来源:Stack.py

示例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()
开发者ID:rohitswarke,项目名称:LinkedListAddition,代码行数:31,代码来源:add_linkedlists.py

示例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")
开发者ID:pombredanne,项目名称:CrackCode,代码行数:6,代码来源:TestLinkedList.py

示例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")
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:8,代码来源:LinkedList_test.py

示例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))
开发者ID:jackchi,项目名称:interview-prep,代码行数:5,代码来源:test_linkedList.py


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