zoukankan      html  css  js  c++  java
  • 队列循环实现(C#)

    C#队列的循环实现:

    View Code
    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;
            }
        }
  • 相关阅读:
    MySql msi安装
    C# TextBox文本内容选中
    SQL 删除时间最靠前的几条数据
    Layui表格工具栏绑定事件失效问题
    Layui我提交表单时,table.reload(),表格会请求2次,是为什么?按下面的做
    table 中数据行循环滚动
    html 3D反转效果
    网页电子表数字样式
    power tool 强制撤销
    GHOST -ntexact 正常还原
  • 原文地址:https://www.cnblogs.com/zhoutk/p/2737699.html
Copyright © 2011-2022 走看看