import time
class MyQueue:
def init(self,size=10):
self._content=[]
self._size=size
self._current=0
def setSize(self,size):
if size<size._current:
for i in range(size,self._current)[::-1]:
del self._content[i]
self._current=size
self._size=size
def put(self,v,timeout=5):
for i in range (timeout):
if self._current<self._size:
self._content.append(v)
self._current=self._current+1
break
time.sleep(1)
else:
print("队列已满,超时放弃")
def get(self,timeout=5):
for i in range (timeout):
if self._content:
self._content=self._current-1
return self._content.pop(0)
time.sleep(1)
else :
print("队列为空,超时放弃")
return None
def show(self):
if self._content:
print(self._content)
else:
print("队列为空")
def empty(self):
self._content=[]
self._current=0
def isEmpty(self):
return not self._content
def isFull(self):
return self._current==self._size
queue=MyQueue(5)
queue.put("a")
queue.put("c")
queue.put("d")
queue.put("e")
queue.put("f")
queue.put("g")
print(queue.get())
print(queue.get())
print(queue.get())
print(queue.get())
print(queue.get())
queue.get()