zoukankan      html  css  js  c++  java
  • C# 堆栈的数据结构 (二)

    堆栈是一种常用的数据结构,并且是线性表操作的子集,即操作受限的线性表。因此需要用到Clist 线性表类

     1   public class CStack
     2     {
     3         private Clist m_List;//创建链表对象实例
     4         //构造函数
     5         public CStack()
     6         {
     7             m_List=new Clist();
     8         }
     9         //压入堆栈
    10         public void Push(int PushValue)
    11         {
    12             m_List.Append(PushValue);//参数:int PushValue 压入堆栈的数据
    13         }
    14         //弹出堆栈数据,如果为空,则取2147483647为int的最大值
    15         public int Pop()
    16         {
    17             // 功能:弹出堆栈数据
    18             int PopValue;
    19             if (!IsNullStack())
    20             {
    21                 //不为空堆栈
    22                 //移动到顶
    23                 MoveTop();
    24                 //取得弹出的数据
    25                 PopValue = GetCurrentValue();
    26                 //删除
    27                 Delete();
    28                 return PopValue;
    29             }
    30             //空的时候为int 类型的最大值
    31             return 2147483647;
    32         }
    33         //判断是否为空的堆栈
    34         public bool IsNullStack()
    35         {
    36             if (m_List.IsNull())
    37             {
    38                 return true;
    39             }
    40             return false;
    41         }
    42         //堆栈的个数
    43         public int StackListCount
    44         {
    45             get { return m_List.ListCount; }
    46         }
    47         //移动到堆栈的底部
    48         public void MoveBottom()
    49         {
    50             m_List.MoveFrist();
    51         }
    52         //移动到堆栈的顶部
    53         public void MoveTop()
    54         {
    55             m_List.MoveLast();
    56         }
    57         //向上移动
    58         public void MoveUp()
    59         {
    60             m_List.MoveNext();
    61         }
    62         //向下移动
    63         public void MoveDown()
    64         {
    65             m_List.MovePrevious();
    66         }
    67         //取得当前的值
    68         public int GetCurrentValue()
    69         {
    70             return m_List.GetCurrentValue();
    71         }
    72         //删除取得当前的结点
    73         public void Delete()
    74         {
    75             m_List.Delete();
    76         }
    77         //清空堆栈
    78         public void Clear()
    79         {
    80             m_List.Clear();
    81         }
    82     }
  • 相关阅读:
    tcp/心跳包
    TCP协议中的三次握手和四次挥手(图解)
    http 中get和post
    xmpp总结
    IOS中http请求使用cookie
    sdwebimage总结
    iOS断言
    Object-C自定义对象NSLog输入信息
    NSTimer你真的会用了吗
    ios中block中的探究
  • 原文地址:https://www.cnblogs.com/Yellowshorts/p/3523604.html
Copyright © 2011-2022 走看看