C# 队列数据结构 (三)

队列是一种先进先出的线性表 因此需要引用Clist线性类

 1   class CQueue
 2     {
 3         private Clist m_list;//构造链表对象实例
 4         public CQueue()//构造函数
 5         {
 6             m_list = new Clist();
 7         }
 8         //入队
 9         public void EnQueue(int DataValue)
10         {
11             //功能:加入队列,这里使用List类的Append方法
12             //尾部添加数据,数据个数加1
13             m_list.Append(DataValue);
14         }
15         //出队
16         public int DeQueue()
17         {
18             int QueValue;
19             if (!IsNull())
20             {
21                 //不为空的队列
22                 //移动到队列的头
23                 m_list.MoveFrist();
24                 //取得当前的值
25                 QueValue = m_list.GetCurrentValue();
26                 //删除出队的数据
27                 m_list.Delete();
28                 return QueValue;
29             }
30             return 2147483647;
31 
32         }
33         //判断队列是否为空
34         public bool IsNull()
35         {
36             return m_list.IsNull();
37         }
38         //清空队列
39         public void Clear()
40         {
41             m_list.Clear();//清空链表
42         }
43         //取得队列的数据个数
44         public int QueueCount
45         {
46             get
47             {
48                 return m_list.ListCount;//取得队列的个数
49             }
50         }
51     }

 

posted @ 2014-01-17 10:26  yellowshorts  阅读(466)  评论(0编辑  收藏  举报