class Customer{
constructor(flag,time,number){
this.vip=flag;
this.time=time;
this.phoneNumber=number;
}
getVip(){
return this.vip;
}
getTime(){
return this.time;
}
getNumber(){
return this.phoneNumber;
}
}
class Queue{
constructor(){
this.Q=[];
this.vipQ=[];
this.notVipQ=[];
}
add(c){
if (c.vip) { //c是Customer的实例
this.vipQ.push(c.phoneNumber);
}else{
this.notVipQ.push(c.phoneNumber);
}
}
getCustomer(){
if (!this.Q.length&&this.notVipQ.length) {
if (!this.vipQ.length) {
this.Q.push(this.notVipQ.shift());
}else{
this.Q.push(this.vipQ.shift());
}
}
}
}
不晓得还要用current实现什么功能,还请各位大神指点!
class queue:
def __init__(self,vip,nor):
if(type(vip)==list and type(nor)==list):
self.vip = vip
self.nor = nor
else :print 'vip and nor must be list'
def addcustom(self,name,phonenumber,ifvip):
if (ifvip):
self.vip.append([name,phonenumber])
else :
self.nor.append([name,phonenumber])
def next(self):
if (self.vip):
n = self.vip[0][0]
del(self.vip[0])
print 'next is ' + n
else :
n = self.nor[0][0]
del(self.nor[0])
print 'next is ' + n
def current(self):
str1 = '现在队列为:'
for i in self.vip:
str1 += i[0]
str1 += ', '
for i in self.nor:
str1 += i[0]
str1 +=', '
print str1用Python试着写了下,不知道算不算满足题目要求……