周末舞会
假设在周末舞会上,男士们和女士们进入舞厅时,各自排成一队。跳舞开始时,依次从男队
和女队的队头上各出一人配成舞伴。规定每个舞曲能有一对跳舞者。若两队初始人数不相同,则较
长的那一队中未配对者等待下一轮舞曲。现要求写一个程序,模拟上述舞伴配对问题。
队列类代码:
public class SeqQueue {
String element[];
int front,rear;
public SeqQueue(int length) {
this.element=new String[length];
this.front=this.rear=0;
}
public boolean isEmpty() {
return this.front==this.rear;
}
public boolean add(String str) {
if(this.front==(this.rear+1)%this.element.length) {
String[] temp=this.element;
this.element= new String[element.length*2];
in