国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
    主站蜘蛛池模板: 昌乐县| 临海市| 大同县| 平南县| 满城县| 杭州市| 重庆市| 如东县| 许昌县| 金沙县| 延长县| 咸阳市| 台江县| 沙坪坝区| 吉木乃县| 崇信县| 庆城县| 邵阳县| 云霄县| 新巴尔虎左旗| 章丘市| 射阳县| 泾源县| 三台县| 辉南县| 仲巴县| 铜山县| 万州区| 金门县| 疏附县| 逊克县| 富顺县| 昂仁县| 灵台县| 台江县| 湖北省| 罗山县| 禹城市| 洪洞县| 两当县| 武隆县|