本文整理汇总了Python中stack.Stack.count方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.count方法的具体用法?Python Stack.count怎么用?Python Stack.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack.Stack
的用法示例。
在下文中一共展示了Stack.count方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stack_count
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def test_stack_count():
s = Stack()
assert_equals(s.count(), 0)
s.push(1)
assert_equals(s.count(), 1)
s.pop()
assert_equals(s.count(), 0)
示例2: Queueky
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
class Queueky():
def __init__(self):
self.__s = Stack()
def enqueue(self, elem):
self.__s.push(elem)
def dequeue(self):
temp = Stack()
cache = Stack()
while self.__s.count() > 1:
temp.push(self.__s.pop())
while temp.count() > 0:
cache.push(temp.pop())
result = self.__s.pop()
self.__s = cache
return result
def is_empty(self):
return self.__s.is_empty()
def top(self):
return self.__s.top()
def count(self):
return self.__s.count()
示例3: test_count
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def test_count(self):
'''Stack - Count items on the stack'''
stack = Stack()
self.assertEqual(0, stack.count())
stack.push("One")
self.assertEqual(1, stack.count())
stack.push("Two")
self.assertEqual(2, stack.count())
示例4: test_push
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def test_push(self):
'''Stack - Push an item onto the stack'''
stack = Stack()
self.assertEqual(stack.count(), 0)
stack.push("pete")
topval = stack.peek()
self.assertEqual(stack.count(), 1)
self.assertEqual("pete", topval)
示例5: test_pop
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def test_pop(self):
'''Stack - Pop an item from the stack'''
stack = Stack()
stack.push("Wendy")
stack.push("Peter")
stack.dump()
self.assertEqual(stack.count(), 2)
answer = stack.pop()
self.assertEqual(answer, "Peter")
self.assertEqual(stack.count(), 1)
示例6: test_peek
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def test_peek():
s = Stack()
assert_equals(s.peek(), None)
s.push(1)
assert_equals(s.peek(), 1)
assert_equals(s.count(), 1)
assert_equals(s.pop(), 1)
示例7: test_is_empty
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def test_is_empty():
s = Stack()
assert_equals(s.is_empty(), True)
s.push(1)
assert_equals(s.is_empty(), False)
s.pop()
assert_equals(s.is_empty(), True)
assert_equals(s.count(), 0)
示例8: dequeue
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def dequeue(self):
temp = Stack()
cache = Stack()
while self.__s.count() > 1:
temp.push(self.__s.pop())
while temp.count() > 0:
cache.push(temp.pop())
result = self.__s.pop()
self.__s = cache
return result
示例9: test_empty_stack
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import count [as 别名]
def test_empty_stack():
s = Stack()
assert_equals(s.is_empty(), True)
assert_equals(s.count(), 0)
assert_equals(s.pop(), None)