public class RecycleQueue<T>
{
public int len;
T[] v;
int max;
int front;
int rear;
public RecycleQueue(int MAXSIZE)
{
max = MAXSIZE;
v = new T[max];
len = 0;
front = 0;
rear = 0;
}
public T this[int i]
{
get
{
return v[(rear - i + max) % max];
}
}
public void test()
{
for (int i = 0; i < max; i++)
{
Console.Write(v[i]+"\t");
}
Console.WriteLine();
}
public bool IsVaildRef(int refLen) {
if (refLen>-1 && refLen <len)
{
return true;
}
return false;
}
//入队操作
public void Push(T value)
{
if ( len ==0)
{
v[rear] = value;
len++;
}
else if (len < max)
{
rear++;
v[rear] = value;
len++;
}
else
{
v[front] = value;
rear = front;
//rear = (rear + 1) % max;
//溢出
front = (front + 1) % max;
}
}
//求队列长度
public int GetLength()
{
return len;
}
}
相关文章
- 01-25SAP QM启用了Physical Sample Management后检验批有哪些特殊地方?
- 01-25UVA 822 Queue and A
- 01-25CodeForces 91B Queue
- 01-25unity, 立即生效动画:Animation.sample()
- 01-25Google单元测试框架gtest之官方sample笔记2--类型参数测试
- 01-25例子:Bluetooth app to device sample
- 01-25队列
- 01-25【Meta learning】Learning to learn: Meta-Critic Networks for sample efficient learning
- 01-25【LeetCode】232 & 225 - Implement Queue using Stacks & Implement Stack using Queues
- 01-253-2-queue_队列_链式存储