C#队列的循环实现:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
class MyQueue <T> { private const int MAXLIMIT = 10; private int count; private int rear, front; private T[] entry = new T[MAXLIMIT]; public MyQueue() { count = 0; rear = MAXLIMIT - 1; front = 0; } public bool empty() { if (count > 0) return false; else return true; } public ErrorCode append(T item) { ErrorCode outcome = ErrorCode.success; if (count < MAXLIMIT) { count++; rear = (rear + 1) == MAXLIMIT ? 0 : rear + 1; entry[rear] = item; } else outcome = ErrorCode.overflow; return outcome; } public ErrorCode serve() { ErrorCode outcome = ErrorCode.success; if (count > 0) { count--; front = (front + 1) == MAXLIMIT ? 0 : front + 1; } else outcome = ErrorCode.underflow; return outcome; } public ErrorCode retrieve(ref T item) { ErrorCode outcome = ErrorCode.success; if (count > 0) { item = entry[front]; } else outcome = ErrorCode.underflow; return outcome; } public bool full() { if (count == MAXLIMIT) return true; else return false; } public int size() { return count; } public void clear() { count = 0; rear = MAXLIMIT - 1; front = 0; } public ErrorCode serve_and_retrieve(ref T item) { ErrorCode outcome = ErrorCode.success; if (count > 0) { count--; item = entry[front]; front = (front + 1) == MAXLIMIT ? 0 : front + 1; } else outcome = ErrorCode.underflow; return outcome; } }