Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //1.使用BCL中的队列
            //Queue<int> queue = new Queue<int>();
            //2.使用自己的顺序队列
            //IQueue<int> queue = new SeqQueue<int>();
            //3.使用自己的链队列
            IQueue<int> queue = new LinkQueue<int>();

            //入队(添加数据)
            queue.Enqueue(23);
            queue.Enqueue(45);
            queue.Enqueue(67);
            queue.Enqueue(89);
            Console.WriteLine(queue.Count);

            int i  = queue.Dequeue(); //出队(取得队首数据并删除)
            Console.WriteLine(i);
            Console.WriteLine(queue.Count);

            int j = queue.Peek();
            Console.WriteLine(j);
            Console.WriteLine(queue.Count);

            queue.Clear();
            Console.WriteLine(queue.Count);

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void EnqueueAndDequeue()
        {
            var students = new Student[]
            {
                new Student {
                    No = 1, Name = "李1", Score = 22.1
                },
                new Student {
                    No = 2, Name = "李2", Score = 32.3
                },
                new Student {
                    No = 3, Name = "李3", Score = 42.5
                }
            };

            var linkQueue = new LinkQueue <Student>();

            foreach (var student in students)
            {
                linkQueue.Enqueue(new Node <Student>(student));
            }


            var deqStudent = new Node <Student>();

            while (deqStudent != null)
            {
                deqStudent = linkQueue.Dequeue();
            }
        }
Exemplo n.º 3
0
    void Start()
    {
        LinkQueue <int> linkQueue = new LinkQueue <int>();

        for (int i = 0; i < 3; i++)
        {
            linkQueue.Enqueue(i);
        }
        print("展示队列顶元素:" + linkQueue.Peek());
        print("队列数量:" + linkQueue.Length());
        for (int i = 0; i < 3; i++)
        {
            print(linkQueue.Dequeue());
        }
    }