• 队列循环实现(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;
            }
        }
  • 相关阅读:
    找工作时写过的部分代码
    python编码格式
    dataframe删掉某列
    结巴分词出现AttributeError: 'float' object has no attribute 'decode'错误
    python转换图片格式
    感受野
    swift3 xib自定义view
    iOS 弹出键盘,输入框上移问题
    支付宝问题
    XCode6.0的iOS免证书真机测试方法(MAC及黑苹果均有效)
  • 原文地址:https://www.cnblogs.com/zhoutk/p/2737699.html
Copyright © 2020-2023  润新知