• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 181  文章 - 15  trackbacks - 0
            <2008年11月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            My Tech blog

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            棧在概念方面確實(shí)沒(méi)有提的必要了。看了數(shù)據(jù)結(jié)構(gòu)的這一部分,就將書中的一小段代碼實(shí)現(xiàn)了。這里用到了標(biāo)準(zhǔn)庫(kù)中的stack。下面就是根據(jù)輸入的十進(jìn)制正數(shù)獲取二進(jìn)制正數(shù)的程序(書上是八進(jìn)制):
             1 #include <stack>
             2 #include <iostream>
             3 using namespace std;
             4 int _tmain(int argc, _TCHAR* argv[])
             5 {
             6     stack<int> binaryStack;
             7     int decimalValue;
             8     cout<<"please input decimal value:";
             9     cin>>decimalValue;
            10     while(decimalValue)
            11     {
            12         binaryStack.push(decimalValue%2);
            13         decimalValue=decimalValue/2;
            14         
            15     }
            16     cout<<"\n"<<"the binary result is:";
            17     while(!binaryStack.empty())
            18     {
            19         int result=(int)binaryStack.top();
            20         binaryStack.pop();
            21         cout<<result;
            22     }
            23     cout<<"\n";
            24     return 0;
            25 }
            另外順便看了一下C#和JAVA,當(dāng)然也支持棧。但是這些東西在我平時(shí)使用的時(shí)候卻很少用到,或者在用到的時(shí)候去“重復(fù)發(fā)明輪子了”。作為一個(gè)經(jīng)典的數(shù)據(jù)類型,棧理應(yīng)是被絕大多數(shù)語(yǔ)言支持的(不知道PB怎樣)。所以在這里要樹立一下“重用輪子”的意識(shí):
            C#的十進(jìn)制轉(zhuǎn)二進(jìn)制實(shí)現(xiàn):
             1 class Class1
             2     {
             3         /// <summary>
             4         /// 應(yīng)用程序的主入口點(diǎn)。
             5         /// </summary>
             6         [STAThread]
             7         static void Main(string[] args)
             8         {
             9             //
            10             // TODO: 在此處添加代碼以啟動(dòng)應(yīng)用程序
            11             //
            12             Stack binaryStack=new Stack();
            13             Console.WriteLine("Please input decimal value:");
            14             String sDecimal=Console.ReadLine();
            15             int decimalValue=Int32.Parse(sDecimal);
            16             while(decimalValue!=0)
            17             {
            18                 binaryStack.Push(decimalValue%2);
            19                 decimalValue=decimalValue/2;
            20             }
            21             Console.WriteLine("The binary result is:");
            22             while(binaryStack.Count!=0)
            23             {
            24                 Console.Write(binaryStack.Pop());
            25             }
            26             Console.WriteLine();
            27         }
            28     }

            JAVA的十進(jìn)制轉(zhuǎn)二進(jìn)制實(shí)現(xiàn):
             1 import java.io.BufferedReader;
             2 import java.io.InputStreamReader;
             3 import java.util.Stack;
             4 public class hello1 {
             5     public static void main(String args[])
             6     {
             7         try {
             8             Stack<Integer> binaryStack=new Stack<Integer>();
             9             int decimalValue;
            10             System.out.println("please input decimal value:");
            11             BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
            12             decimalValue=Integer.parseInt(bufferedReader.readLine());
            13             while(decimalValue!=0)
            14             {
            15                 binaryStack.push(decimalValue%2);
            16                 decimalValue=decimalValue/2;
            17             }
            18             System.out.println("the binary result is:");
            19             while(!binaryStack.empty())
            20             {
            21                 System.out.print(binaryStack.pop());
            22             
            23             }
            24         } catch (Exception e) {
            25             // TODO Auto-generated catch block
            26             e.printStackTrace();
            27         }
            28         
            29         
            30     }
            31     }
            通過(guò)比較,會(huì)發(fā)現(xiàn)C#不大有“棧”的感覺(jué),JAVA和C++更貼近于《數(shù)據(jù)結(jié)構(gòu)》中對(duì)于數(shù)據(jù)類型“棧”的操作的定義。另外支持模板或者范型的特點(diǎn)讓人用起來(lái)總會(huì)感覺(jué)十分舒服。在這里提醒自己:以后這三種語(yǔ)言有“棧”可用了!
            posted on 2007-06-11 22:11 littlegai 閱讀(198) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 我的讀書筆記
            久久久久久国产精品免费免费| 佐藤遥希在线播放一二区 | 久久人人爽人人爽人人片AV不 | 亚洲人AV永久一区二区三区久久 | 久久久久久亚洲精品无码| 国内精品伊人久久久久妇| 亚洲一本综合久久| 99久久人妻无码精品系列| 精品多毛少妇人妻AV免费久久| 久久人人爽人人人人片av| …久久精品99久久香蕉国产| 久久久老熟女一区二区三区| 久久强奷乱码老熟女网站| 香港aa三级久久三级| 久久亚洲AV成人无码国产| 香蕉久久久久久狠狠色| 久久夜色精品国产噜噜亚洲a| 久久精品一本到99热免费| 欧美成人免费观看久久| 欧美大战日韩91综合一区婷婷久久青草| 久久综合狠狠综合久久激情 | 久久精品国产亚洲沈樵| 久久免费精品视频| 久久精品国产只有精品66| 久久99国产乱子伦精品免费| 久久久久亚洲av综合波多野结衣| 国产女人aaa级久久久级| 欧美日韩精品久久久久| 久久久www免费人成精品| 亚洲国产成人精品久久久国产成人一区二区三区综 | 一本一本久久a久久综合精品蜜桃| 欧美久久天天综合香蕉伊| 久久97久久97精品免视看秋霞| 欧美久久久久久| 一本色道久久综合狠狠躁篇| 久久亚洲精品无码播放| 久久亚洲欧洲国产综合| 亚洲国产成人久久精品99 | 久久久久亚洲精品天堂久久久久久| 久久综合狠狠综合久久激情 | 久久精品青青草原伊人|