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


Python LinkedList.insert方法代码示例

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


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

示例1: test_insert_two

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def test_insert_two():
    l_list = LinkedList()
    l_list.insert("David")
    l_list.insert("Thomas")
    assert l_list.head.get_data() == "Thomas"
    head_next = l_list.head.get_next()
    assert head_next.get_data() == "David"
开发者ID:ataicher,项目名称:learn_to_code,代码行数:9,代码来源:LinkedListTest.py

示例2: main

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def main():
    #Create list of names
    listOfNames = { "Tom", "Harry","Susan","Ethan","Willy","Shaina"}

    #Create linkedlist object
    testinglist = LinkedList()

    #Test insertion method
    for name in listOfNames:
        testinglist.insert(name)

    #Test size of list
    print testinglist.size()

    #Test print list
    testinglist.printList()

    #Test Deletion of head node
    testinglist.delete("Tom")

    #Test Deletion method:
    testinglist.delete("Susan")
    testinglist.printList()

    #Test search list
    testinglist.search("Willy")
开发者ID:ethanpierce,项目名称:DrZhao,代码行数:28,代码来源:unitTestLinkedList.py

示例3: main

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def main():
    ll = LinkedList()
    data = [char for char in 'FOLLOW UP']
    for char in data[::-1]:
        node = Node(char)
        ll.insert(node)
    remove_duplicates(ll.head)
    print "%s" % ll == "%s" % ['F', 'O', 'L', 'W', ' ', 'U', 'P']
开发者ID:xiaotdl,项目名称:CodingInterview,代码行数:10,代码来源:2_1_remove_duplicates.py

示例4: main

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def main():
    ll = LinkedList()
    data = [char for char in '123456789']
    for char in data[::-1]:
        node = Node(char)
        ll.insert(node)
    print ll
    print ll.size()
    print kth_tolast(ll.head, 5).val == '123456789'[-5]
开发者ID:xiaotdl,项目名称:CodingInterview,代码行数:11,代码来源:2_2_kth_tolast.py

示例5: test_searchNone

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def test_searchNone():
    l_list = LinkedList()
    l_list.insert("Jacob")
    l_list.insert("Pallymay")
    # make sure reg search works
    found = l_list.search("Jacob")
    assert found.get_data() == "Jacob"
    with pytest.raises(ValueError):
        l_list.search("Vincent")
开发者ID:ataicher,项目名称:learn_to_code,代码行数:11,代码来源:LinkedListTest.py

示例6: __init__

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
class Stack:
    def __init__(self):
        self.llist = LinkedList()

    def push(self, item):
        self.llist.insert(0, item)

    def pop(self):
        item = iter(self.llist).next()
        self.llist.remove(item)
        return item
开发者ID:crazy2k,项目名称:algorithms,代码行数:13,代码来源:stack.py

示例7: main

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def main():
    selected = None
    ll = LinkedList()
    data = [char for char in '3728511296']
    for char in data[::-1]:
        node = Node(char)
        ll.insert(node)
        if int(char) == 5:
            selected = node
    print ll
    partition_linkedlist(selected)
    print ll, type(ll)
    print "%s" % ll == "%s" % list('12346789')
开发者ID:xiaotdl,项目名称:CodingInterview,代码行数:15,代码来源:2_4_partition_linkedlist.py

示例8: main

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def main():
    tobedeleted = None
    ll = LinkedList()
    data = [char for char in '123456789']
    for char in data[::-1]:
        node = Node(char)
        ll.insert(node)
        if int(char) == 5:
            tobedeleted = node
    print ll
    delete_node(tobedeleted)
    print ll, type(ll)
    print list('12346789'), type(list('12346789'))
    print "%s" % ll == "%s" % list('12346789')
开发者ID:xiaotdl,项目名称:CodingInterview,代码行数:16,代码来源:2_3_delete_node.py

示例9: test_delete_next_reassignment

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [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:ataicher,项目名称:learn_to_code,代码行数:11,代码来源:LinkedListTest.py

示例10: test_delete_value_not_in_list

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [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:ataicher,项目名称:learn_to_code,代码行数:9,代码来源:LinkedListTest.py

示例11: main

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def main():
    """ don't modify this function. even if you do I have a copy of the original to test with """
    mylist = LinkedList()

    # add some initial nodes
    mylist.append(10)
    mylist.append(20)
    mylist.append(30)
    
    # this should display 10 20 30
    print(mylist)

    # add some nodes to the front
    mylist.prepend(0)
    mylist.prepend(-10)

    # this should display: -10 0 10 20 30
    print(mylist)

    mylist.update(0, -20)  # change -10 to -20
    mylist.insert(2, 5)    # insert 5 between 0 and 10
    mylist.insert(5, 25)   # insert 25 between 20 and 30
    mylist.remove(1)       # remove the 0

    # this should display: -20 5 10 20 25 30
    print(mylist)

    mylist.remove(3)        # removes 20
    mylist.append(40)       # add 40 to the end
    mylist.append(50)       # add 50 to the end
    mylist.update(5, 45)    # update 40 to 45
    mylist.remove(5)        # remove 45
    mylist.update(5, 55)    # update 50 to 55
    mylist.prepend(-30)     # add -30 to the front

    # this should display -30 -20 5 10 25 30 55
    print(mylist)
开发者ID:lumo-cha,项目名称:datastructures-linkedlists,代码行数:39,代码来源:driver.py

示例12: test_delete

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [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:ataicher,项目名称:learn_to_code,代码行数:11,代码来源:LinkedListTest.py

示例13: test_nextNode

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def test_nextNode():
    l_list = LinkedList()
    l_list.insert("Jacob")
    l_list.insert("Pallymay")
    l_list.insert("Rasmus")
    assert l_list.head.get_data() == "Rasmus"
    head_next = l_list.head.get_next()
    assert head_next.get_data() == "Pallymay"
    last = head_next.get_next()
    assert last.get_data() == "Jacob"
开发者ID:ataicher,项目名称:learn_to_code,代码行数:12,代码来源:LinkedListTest.py

示例14: test_positive_search

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def test_positive_search():
    l_list = LinkedList()
    l_list.insert("Jacob")
    l_list.insert("Pallymay")
    l_list.insert("Rasmus")
    found = l_list.search("Jacob")
    assert found.get_data() == "Jacob"
    found = l_list.search("Pallymay")
    assert found.get_data() == "Pallymay"
    found = l_list.search("Jacob")
    assert found.get_data() == "Jacob"
开发者ID:ataicher,项目名称:learn_to_code,代码行数:13,代码来源:LinkedListTest.py

示例15: test_corrupt_loop

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insert [as 别名]
def test_corrupt_loop():
  l_list = LinkedList()
  l_list.insert('E')
  l_list.insert('D')
  l_list.insert('C')
  l_list.insert('B')
  l_list.insert('A')
  print l_list
  node1 = l_list.search('E')
  node2 = l_list.search('C')
  node1.set_next(node2)
  node = l_list.corrupt_loop()
  print node
开发者ID:ataicher,项目名称:learn_to_code,代码行数:15,代码来源:LinkedListTest.py


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