您的位置:首页 > 其它

算法 第四版 1.3.39 环形缓冲区

2017-09-04 16:39 218 查看
public class RingBuffer<Item> {

/**
* @param args
*/
private Item[] a;
private int first=0, last=0;
public RingBuffer(int N){
a = (Item[]) new Object
;
}
public boolean isEmpty(){ return first == last; }
public boolean isFull(){ return (first+1)%a.length == last%a.length; }
public void putProduction(Item item){
while(isFull());  //当满的时候,等待
a[(first++)%a.length] = item;
}
public Item getProduction(){
while(isEmpty()); //当空的时候,等待
return a[(last++)%a.length];
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: