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

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

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

2024-07-21 02:22:15
字體:
供稿:網(wǎng)友
  • 本文來源于網(wǎng)頁設(shè)計愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。
  • c#數(shù)據(jù)結(jié)構(gòu)篇(二)堆棧



                 作者: 寒羽狼 (dark_slaer_tang)



            煙快沒有了,別人都說煙有害,但對與我可是必不可少的,呵呵。。,抽一根煙程序就寫出來了,好了,再加把勁,我們再完成堆棧,其實堆棧和線性表沒什么大的區(qū)別,堆棧其實是一種特殊的線性表,使用push 壓輸入數(shù)據(jù),pop 彈出數(shù)據(jù),才用,先進(jì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())
       {



        //不為空堆棧



        //移動到頂







        movetop();



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



       //刪除



        delete();
        return popvalue;

       }



       //  空的時候為 int 類型的最大值



       return 2147483647;
      }



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



       return false ;
      }



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



      public int stacklistcount
      {   



        
       get
       {
        return m_list.listcount ;
       }

      }



      /// <summary>
      /// 移動到堆棧的底部
      /// </summary>



      public void movebottom()
      {



            m_list.movefrist ();
      }



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



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



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



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



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



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




    public void clear()



    {



         m_list.clear();



    }




    }
    }



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


    發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 武穴市| 新龙县| 永福县| 虎林市| 花莲市| 阳江市| 大丰市| 张家港市| 佛冈县| 琼结县| 山西省| 龙江县| 阿荣旗| 城固县| 福贡县| 泾源县| 天峨县| 锦屏县| 平江县| 石城县| 咸丰县| 鸡泽县| 沈丘县| 墨玉县| 察哈| 安平县| 江源县| 新郑市| 闽清县| 南乐县| 余姚市| 馆陶县| 怀柔区| 丹凤县| 三门峡市| 内乡县| 修武县| 台江县| 五指山市| 正定县| 绥江县|