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


Python LinkedList.push_back方法代码示例

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


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

示例1: test_clear

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
 def test_clear(self):
     llist = LinkedList()
     for i in xrange(10):
         llist.push_back(i)
     llist.clear()
     self.assertFalse(bool(llist))
     self.assertIsNone(llist.back())
开发者ID:sthe0,项目名称:task3,代码行数:9,代码来源:test.py

示例2: test_insert_before

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
 def test_insert_before(self):
     llist = LinkedList()
     for i in xrange(10):
         llist.push_back(i)
     for item in llist:
         if item.value % 2 == 0:
             llist.insert_before(item, item.value)
     self.assertEqual([0,0,1,2,2,3,4,4,5,6,6,7,8,8,9], [node.value for node in llist])
开发者ID:sthe0,项目名称:task3,代码行数:10,代码来源:test.py

示例3: test_insert_after

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
 def test_insert_after(self):
     llist = LinkedList()
     for i in xrange(10):
         llist.push_back(i)
     for item in llist:
         if item.value % 2 == 0:
             llist.insert_after(item, item.value - 1)
     self.assertEqual([0,-1,1,2,1,3,4,3,5,6,5,7,8,7,9], [node.value for node in llist])
开发者ID:sthe0,项目名称:task3,代码行数:10,代码来源:test.py

示例4: test_pop_back

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
 def test_pop_back(self):
     llist = LinkedList()
     for i in xrange(10):
         llist.push_back(i)
     i = 9
     while llist:
         item = llist.pop_back()
         self.assertEqual(item, i)
         i -= 1
开发者ID:sthe0,项目名称:task3,代码行数:11,代码来源:test.py

示例5: test_non_empty_list

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
 def test_non_empty_list(self):
     llist = LinkedList()
     llist.push_back(1)
     self.assertIsNotNone(llist.next())
     self.assertIsNotNone(llist.prev())
     self.assertEqual(llist.prev(), llist.back())
     self.assertEqual(llist.next(), llist.front())
     self.assertEqual(llist.back(), llist.front())
     self.assertTrue(bool(llist))
开发者ID:sthe0,项目名称:task3,代码行数:11,代码来源:test.py

示例6: test_remove

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
    def test_remove(self):
        llist = LinkedList()
        for i in xrange(10):
            llist.push_back(i)
        for item in llist:
            if item.value % 2 == 0:
                llist.remove(item)
        self.assertEqual([node.value for node in llist], range(1,10,2))

        for i in xrange(5):
            llist.remove(llist.back())
        self.assertFalse(bool(llist))
开发者ID:sthe0,项目名称:task3,代码行数:14,代码来源:test.py

示例7: RuleList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
class RuleList(object):
    def __init__(self, max_size = 10):
        self.__list = LinkedList()
        self.__cmp = BoolCmp(1e-9)
        self.__max_size = max_size
        self.__rule_set = set()

    def insert(self, informativity, rule):
        if rule in self.__rule_set:
            return
        self.__rule_set.add(rule)

        if not self.__list or self.__cmp(self.__list.back().value[0], informativity) > 0:
            self.__list.push_back([informativity, rule])
        else:
            for node in self.__list:
                if self.__cmp(node.value[0], informativity) > 0:
                    continue
                if self.__cmp(node.value[0], informativity) == 0:
                    node.value.append(rule)
                if self.__cmp(node.value[0], informativity) < 0:
                    self.__list.insert_before(node, [informativity, rule])
                break
        if len(self.__rule_set) - (len(self.__list.back().value) - 1) >= self.__max_size:
            for item in self.__list.back().value[1:]:
                self.__rule_set.remove(item)
            self.__list.remove(self.__list.back())

    def clear(self):
        self.__list = LinkedList()
        self.__rule_set = set()

    def __iter__(self):
        for node in self.__list:
            for item in node.value[1:]:
                yield node.value[0], item

    def __len__(self):
        return len(self.__rule_set)

    def __contains__(self, rule):
        return rule in self.__rule_set
开发者ID:sthe0,项目名称:task3,代码行数:44,代码来源:rulebuilder.py

示例8: test_push_back

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import push_back [as 别名]
 def test_push_back(self):
     llist = LinkedList()
     for i in xrange(10):
         llist.push_back(i)
     for i, node in enumerate(llist):
         self.assertEqual(node.value, i)
开发者ID:sthe0,项目名称:task3,代码行数:8,代码来源:test.py


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