首页 > 试题广场 >

某饭店要开发一个排队软件。非VIP用户需要排队,先到先得。V

[问答题]
某饭店要开发一个排队软件。非VIP用户需要排队,先到先得。VIP用户可以插队,但是VIP用户之间需要按到达时间先后排队。
要求实现:①addCustomer(String phoneNumber)函数②有空位时获取排到的用户③用户进店排队时的函数current()
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实现什么功能,还请各位大神指点!
发表于 2017-08-05 09:56:31 回复(0)
这家店会倒闭。
发表于 2017-04-03 11:19:04 回复(2)

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试着写了下,不知道算不算满足题目要求……
编辑于 2015-09-30 14:37:14 回复(0)