#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#define MAX_BUFFER 512 //buffer最大容量
#define NO_MEANING 99999999 //当某顺串已经全部处理完时,给败方树外部节点填充这个超大值
#define MAX 10 //最大选手数目
/********************* 缓冲区类,用环状数组实现的队列来实现之 ********************/
//设置头指针front,尾指针rear
//插入在rear处,删除在front处
template <class Elem> class Buffer{
private:
Elem * buf; //存放元素的数组
int front, rear;
int n; //buffer中当前元素的数目
public:
//constructor
Buffer(){
buf = new Elem [MAX_BUFFER];
front = 0;
rear = 0;
n = 0;
}
//destructor
~Buffer(){
delete buf;
}
//判断buffer是否为空
bool isEmpty(){
return (n==0);
}
//判断buffer是否满
bool isFull(){
return (n==MAX_BUFFER);
}
//列出buffer中所有的元素
//假设元素类型为内建类型
void list(){
if (isEmpty()){
cout<<"no data!"<<endl<<endl;
return;
}
int temp = front;
for(int i = 0; i < n; i++){
cout<<buf[temp % MAX_BUFFER]<<" ";
temp++;
}
cout<<endl<<endl;
}
//往buffer中插入元素x
bool insert(Elem x){
if(isFull()==false){//非满
buf[rear] = x;
rear = (rear+1)%MAX_BUFFER;
n++;
return true;
}
else{
cout<<"BUFFER FULL!"<<endl;
return false;
}
}
//从buffer中读取元素x,并在buffer中删除它
bool read(Elem & x){
if(isEmpty()==false){//非空
x = buf[front];
front = (front+1)%MAX_BUFFER;
n--;
return true;
}
else{
cout<<"BUFFER EMPTY!"<<endl;
return false;
}
}
void flush(FILE * outputFile){
//写入输出文件
int temp = front;
for(int i = 0; i < n; i++){
fprintf(outputFile,"%d ", buf[temp % MAX_BUFFER]);
//cout<<buf[temp % MAX_BUFFER]<<" ";
temp++;
}
//清零
n = 0;
front = 0;
rear = 0;
}
};
/******** 全局Winner函数&#x