国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > 綜合 > 正文

C#數(shù)據(jù)結(jié)構(gòu)篇(二 堆棧) killertang(原作)

2024-07-21 02:28:06
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友


c#數(shù)據(jù)結(jié)構(gòu)篇(二)堆棧



             作者: 寒羽狼 (dark_slaer_tang)



        煙快沒有了,別人都說煙有害,但對(duì)與我可是必不可少的,呵呵。。,抽一根煙程序就寫出來(lái)了,好了,再加把勁,我們?cè)偻瓿啥褩#鋵?shí)堆棧和線性表沒什么大的區(qū)別,堆棧其實(shí)是一種特殊的線性表,使用push 壓輸入數(shù)據(jù),pop 彈出數(shù)據(jù),才用,先進(jìn)后出的原則,就這么簡(jiǎn)單。前面已經(jīng)寫好了list 類,在這里我們可以調(diào)用它。代碼如下:



using system;



namespace list
{
/// <summary>
/// 堆棧類
/// </summary>

public class cstack
{  




  //調(diào)用鏈表類
  private  clist m_list;
  



  public cstack()
  {



  //構(gòu)造函數(shù)




   m_list=new clist();



  }



  /// <summary>
  /// 壓入堆棧
  /// </summary>
  
  public void push(int pushvalue)
  {
      //參數(shù): int pushvalue 壓入堆棧的數(shù)據(jù)



      m_list.append (pushvalue);
            
  }



  /// <summary>
  /// 彈出堆棧數(shù)據(jù),如果為空,則取得 2147483647 為 int 的最大值;
  /// </summary>
  
  public int pop()
  {
  //功能:彈出堆棧數(shù)據(jù)



  int popvalue;
   
   if (!isnullstack())
   {



    //不為空堆棧



    //移動(dòng)到頂







    movetop();



    //取得彈出的數(shù)據(jù)
    popvalue=getcurrentvalue();



   //刪除



    delete();
    return popvalue;

   }



   //  空的時(shí)候?yàn)?int 類型的最大值



   return 2147483647;
  }



  /// <summary>
  /// 判斷是否為空的堆棧
  /// </summary>
  
  public bool isnullstack()
  {   
   
   if ( m_list.isnull() )
   return true ;



   return false ;
  }



  /// <summary>
  /// 堆棧的個(gè)數(shù)
  /// </summary>



  public int stacklistcount
  {   



    
   get
   {
    return m_list.listcount ;
   }

  }



  /// <summary>
  /// 移動(dòng)到堆棧的底部
  /// </summary>



  public void movebottom()
  {



        m_list.movefrist ();
  }



  /// <summary>
  /// 移動(dòng)到堆棧的top
  /// </summary>
  
  public void movetop()
  {
   m_list.movelast  ();
  }



  /// <summary>
  /// 向上移動(dòng)
  /// </summary>
  
  public void moveup()
  {
   m_list.movenext();
  }



  /// <summary>
  /// 向上移動(dòng)
  /// </summary>
  
  public void movedown()
  {
   m_list.moveprevious() ;
  }



  /// <summary>
  /// 取得當(dāng)前的值
  /// </summary>
  
   public int  getcurrentvalue()
  {
   return m_list.getcurrentvalue ();
  }



  /// <summary>
  /// 刪除取得當(dāng)前的結(jié)點(diǎn)
  /// </summary>
  
  public void delete()
  {
   m_list.delete ();
  }



  /// <summary>
  /// 清空堆棧
  /// </summary>




public void clear()



{



     m_list.clear();



}




}
}



     使用先前的鏈表類,就可以輕松的完成堆棧類,除了基本的,pop,push 方法外,還提供,movebottom,movetop,moveup,movedown ,來(lái)訪問堆棧中的數(shù)據(jù),使用getcurrentvalue方法,來(lái)取得數(shù)據(jù)的值,可以執(zhí)行更多的操作,呵呵,就這么簡(jiǎn)單。to be continue.

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 涞水县| 桃园市| 贵溪市| 牙克石市| 淮南市| 岗巴县| 嘉义县| 随州市| 太湖县| 江华| 山阴县| 芒康县| 甘德县| 防城港市| 西昌市| 紫金县| 通化县| 泗水县| 乌拉特前旗| 镇远县| 宁津县| 铜川市| 太湖县| 紫金县| 电白县| 井陉县| 定安县| 石首市| 双流县| 芒康县| 温泉县| 阿勒泰市| 卓尼县| 互助| 清涧县| 株洲市| 拜城县| 郓城县| 驻马店市| 陵水| 崇明县|