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


Python LinkedList.getSize方法代码示例

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


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

示例1: __init__

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import getSize [as 别名]
class Queue:
    def __init__(self):
        self.__elements = LinkedList()

    # Adds an element to this queue
    def enqueue(self, e):
        self.__elements.add(e)
    
    # Removes an element from this queue
    def dequeue(self):
        if self.getSize() == 0:
            return None
        else:
            return self.__elements.removeAt(0)
    
    # Return the size of the queue
    def getSize(self):
        return self.__elements.getSize()
    
    # Returns a string representation of the queue
    def __str__(self):
        return self.__elements.__str__()

    # Return true if queue is empty 
    def isEmpty(self):
        return self.getSize() == 0
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:28,代码来源:Queue.py

示例2: comment

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import getSize [as 别名]
    else:
        comment("FAIL -> " + test_name +"\n __str__ debe devolver una lista de caracteres (string)")
        grade(0)
except:
    e = sys.exc_info()[1]
    comment("FAIL -> " + test_name + "\n" + str(e))
    grade(0)


# Check empty list - getSize


try:
    test_name = 'LinkedList vacia: getSize()'
    l = LinkedList()
    if l.getSize() == 0:
        comment("OK -> " + test_name)
        grade(points['ll_vacia_getsize'])
    else:
        comment("FAIL -> " + test_name +"\nsize debe ser  0 cuando la lista esta vacia")
        grade(0)
except:
    e = sys.exc_info()[1]
    comment("FAIL -> " + test_name + "\n" + str(e))
    grade(0)



# Check one element list - insertAfter

开发者ID:emiliogq,项目名称:pyrobot,代码行数:31,代码来源:joc_proves_LinkedList.py

示例3: print

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import getSize [as 别名]
list.add("America") # Add it to the list
print("(1)", list)

list.insert(0, "Canada") # Add it to the beginning of the list
print("(2)", list)

list.add("Russia") # Add it to the end of the list
print("(3)", list)

list.addLast("France") # Add it to the end of the list
print("(4)", list)

list.insert(2, "Germany") # Add it to the list at index 2
print("(5)", list)

list.insert(5, "Norway") # Add it to the list at index 5
print("(6)", list)

list.insert(0, "Poland") # Same as list.addFirst("Poland")
print("(7)", list)

# Remove elements from the list
list.removeAt(0) # Remove the element at index 0
print("(8)", list)

list.removeAt(2) # Remove the element at index 2
print("(9)", list)

list.removeAt(list.getSize() - 1) # Remove the last element
print("(10)", list)
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:32,代码来源:TestLinkedList.py

示例4: TestLinkedList

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import getSize [as 别名]
class TestLinkedList(unittest.TestCase):
    def setUp(self):
        self.linkedList = LinkedList()

    def test_0(self):
        print("{} Can create linked list object".format(inspect.stack()[0][3]))
        self.assertTrue(type(self.linkedList) is LinkedList)

    def test_1(self):
        print("{} Newly created linked list, value and next should be null".format(inspect.stack()[0][3]))
        last = self.linkedList.getNext()
        self.assertEqual(last.value, None)
        self.assertEqual(last.next, None)

    def test_2(self):
        print("{} Newly created list, should be empty".format(inspect.stack()[0][3]))
        self.assertTrue(self.linkedList.isEmpty())

    def test_3(self):
        print("{} After one added, list size should be one".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.assertEqual(self.linkedList.getSize(), 1)

    def test_4(self):
        print("{} After two added, list size should be two".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.getSize(), 2)

    def test_5(self):
        print("{} After one added, first index search should return value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.assertEqual(self.linkedList.searchValueAt(0),1)

    def test_6(self):
        print("{} After one added, second index search should return null".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.assertEqual(self.linkedList.searchValueAt(1),None)

    def test_7(self):
        print("{} When two values are added, second index search should return second value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.searchValueAt(1),2)

    def test_8(self):
        print("{} When two values are added, first index search should return first value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.searchValueAt(0),1)

    def test_9(self):
        print("{} Remove first node on empty list, should return null".format(inspect.stack()[0][3]))
        self.assertEqual(self.linkedList.removeAtInd(0), None)

    def test_10(self):
        print("{} After one added then remove first node, list should be empty".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.removeAtInd(0)
        self.assertTrue(self.linkedList.isEmpty())

    def test_11(self):
        print("{} After one added then remove first node, then add another value, first index should have second value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.removeAtInd(0)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.searchValueAt(0),2)

    def test_12(self):
        print("{} After two values added then second value removed, length of list should be one".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(1)
        self.assertEqual(self.linkedList.getSize(),1)

    def test_13(self):
        print("{} After two values added then value at third index removed, length of list should be two".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(2)
        self.assertEqual(self.linkedList.getSize(),2)

    def test_14(self):
        print("{} After two values added then second value removed, first index should be first value and value of second index should be null".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(1)
        self.assertEqual(self.linkedList.searchValueAt(1),None)
        self.assertEqual(self.linkedList.searchValueAt(1),None)

    def test_15(self):
        print("{} After two added then remove first node, length should be one".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(0)
        self.assertEqual(self.linkedList.getSize(),1)

    def test_16(self):
        print("{} After two values added then remove first, value at first index should be second value pushed".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
#.........这里部分代码省略.........
开发者ID:jackreichert,项目名称:exploring-algorithms,代码行数:103,代码来源:testingLinkedList.py


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