本文整理汇总了Python中vector.Vector.size方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.size方法的具体用法?Python Vector.size怎么用?Python Vector.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import size [as 别名]
class Queue:
def __init__(self):
self.__queue = Vector()
# Adds value to the end of the Queue.
# Complexity: O(1)
def push(self, value):
self.__queue.add(value)
# Returns value from the front of the Queue and removes it.
# Complexity: O(1)
def pop(self):
if self.__queue.size() > 0:
first_elemet = self.__queue.get(0)
temp_vector = Vector()
for i in range(0, self.__queue.size()):
if i > 0:
temp_vector.add(self.__queue.get(i))
self.__queue = temp_vector
return first_elemet
else:
return None
# Returns value from the front of the Queue without removing it.
# Complexity: O(1)
def peak(self):
if self.__queue.size != 0:
return self.__queue.get(0)
return None
# Returns the number of elements in the Queue.
# Complexity: O(1)
def size(self):
return self.__queue.size()
def getQueue(self):
return self.__queue.getVector()
示例2: Vector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import size [as 别名]
from vector import Vector
if __name__ == '__main__':
myVector = Vector()
myVector.add('numberOne')
assert myVector.size() == 1
assert myVector.capacity() == 20
myVector = Vector()
myVector.add('numberOne')
myVector.add('numberTwo')
assert myVector.size() == 2
assert myVector.capacity() == 20
myVector = Vector()
myVector.add('numberOne')
assert myVector.pop() == 'numberOne'
assert myVector.size() == 0
assert myVector.capacity() == 20
myVector = Vector()
myVector.add('numberOne')
myVector.add('numberTwo')
assert myVector.pop() == 'numberTwo'
assert myVector.pop() == 'numberOne'
assert myVector.size() == 0
assert myVector.capacity() == 20
myVector = Vector()
myVector.insert(0, 'Hello')
示例3: int
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import size [as 别名]
# test if vector.py is callable externally and if it works well
import sys, os
if os.getcwd() not in sys.path:
sys.path.append(os.getcwd())
from vector import Vector
# run-time loopy
instr = 1
while instr > 0:
instr = int(input('(0)EXIT\n(1)INSERT\n(2)ADD\n(3)GET\n(4)REMOVE\n(5)POP\n(6)SIZE\n(7)CAPACITY\n'))
if instr == 1:
ind = int(input('Index?\n'))
val = input('Value?\n')
print (Vector.insert(ind, val))
elif instr == 2:
val = input ('Value?\n')
print (Vector.add(val))
elif instr == 3:
ind = int(input('Index?\n'))
print (Vector.get(ind))
elif instr == 4:
ind = int(input('Index?\n'))
print (Vector.remove(ind))
elif instr == 5:
print (Vector.pop())
elif instr == 6:
print (Vector.size())
elif instr == 7:
print (Vector.capacity())