码迷,mamicode.com
首页 > 其他好文 > 详细

05 1 栈与队列 栈的实现与Stack类

时间:2017-03-05 19:20:23      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:lap   ica   color   images   ima   pop   清空   closed   技术   

技术分享

 技术分享

技术分享
 1 /// <summary>
 2 /// 自定义栈
 3 /// </summary>
 4 class CStack {
 5 
 6     /// <summary>
 7     /// 存储数据的数组
 8     /// </summary>
 9     private ArrayList m_arrayList;
10     /// <summary>
11     /// 栈顶索引
12     /// </summary>
13     private int m_top;
14 
15     public CStack() {
16         m_arrayList = new ArrayList();
17         m_top = -1;
18     }
19 
20     /// <summary>
21     /// 栈的元素数量
22     /// </summary>
23     public int Count {
24         get {
25             return m_arrayList.Count;
26         }
27     }
28 
29     /// <summary>
30     /// 入栈
31     /// </summary>
32     public void Push(object item) {
33         m_arrayList.Add(item);
34         m_top++;
35     }
36 
37     /// <summary>
38     /// 出栈
39     /// </summary>
40     public object Pop() {
41         object obj = m_arrayList[m_top];
42         m_arrayList.RemoveAt(m_top);
43         m_top--;
44         return obj;
45     }
46 
47     /// <summary>
48     /// 取栈顶
49     /// </summary>
50     public object Peek() {
51         return m_arrayList[m_top];
52     }
53 
54     /// <summary>
55     /// 清空
56     /// </summary>
57     public void Clear() {
58         m_arrayList.Clear();
59         m_top = -1;
60     }
61 }
CStack

 

05 1 栈与队列 栈的实现与Stack类

标签:lap   ica   color   images   ima   pop   清空   closed   技术   

原文地址:http://www.cnblogs.com/revoid/p/6506105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!