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;
            }
        }
  • 相关阅读:
    struts2学习总结
    常用html
    p6spy結合SQL Profiler监控和剖析数据库操作
    ZK 上傳圖片和顯示圖片(保存在文件夹)
    c3p0学习JdbcUtil工具类
    时间的复杂度和空间的复杂度
    ASP.NET后台获取url
    html中offsetTop、clientTop、scrollTop、offsetTop各属性介绍
    ASP.NET文件的下载
    C#牛人要具备的知识
  • 原文地址:https://www.cnblogs.com/zhoutk/p/2737699.html
Copyright © 2011-2022 走看看