当前位置: 代码迷 >> C# >> C#实现行列的基本操作
  详细解决方案

C#实现行列的基本操作

热度:84   发布时间:2016-05-05 04:36:28.0
C#实现队列的基本操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
   
    class Queue
    {
        
        private int font = 0;
        private int rear = 0;
        private int size = 0;
        int[] queue = new int[100];
        public int isPan()
        {
            if (queue.Length == 100)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }


        public int getSize() 
        {
            size = queue.Length;
            return size;
        }


        public void RuDui(int i) 
        {
            if (isPan() == 0)
            {
                Console.WriteLine("抱歉队列已满,无法入队!");
            }
            else
            {
                queue[rear] = i;
                size++;
                rear++;
            }
            
        }


        public void ChuDui()
        {
            Console.WriteLine(queue[font] + "出队");
            size--;
            font++;
        }
    }

}



========================================================================================


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class ClassMain
    {
        static void Main()
        {
            Queue q = new Queue();
            Console.WriteLine("队列中总共有:" + q.getSize() + "个元素");
            q.RuDui(5);
            q.ChuDui();
            Console.Read();
        }
    }
}

  相关解决方案