#!/usr/bin/python
#coding=utf-8
import Queue
import random
class Park(object):
def __init__(self,max=10):
self.max = max
self.size=self.max
self.queue=Queue.Queue(self.max)
self.park_db={}
while self.queue.full() is not True:
i = random.randint(1,10000)
print 'init queue\n'
self.queue.put(i)
def put(self,num):
if self.queue.empty() :
print 'queue is empty!!'
return -1
else:
num_park = self.queue.get_nowait()
self.park_db.setdefault(num_park,num)
return num_park
def get(self,num_park):
if self.queue.full():
return -1
else:
num_car = self.park_db.get(num_park)
self.queue.put(num_park)
return num_car
if __name__ == '__main__':
i=0
nums=[]
p = Park()
print '\n start put car \n'
while i < 10:
nums.append(p.put(i))
i=i+1
print '\n put car end\n'
for i in nums:
num = p.get(i)
# nums.remove(i)
print i ,'---I--',num
if len(nums) !=0:
print '\n Test failture!\n'