• <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
            <2009年4月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            My Tech blog

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            棧在概念方面確實沒有提的必要了。看了數據結構的這一部分,就將書中的一小段代碼實現了。這里用到了標準庫中的stack。下面就是根據輸入的十進制正數獲取二進制正數的程序(書上是八進制):
             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,當然也支持棧。但是這些東西在我平時使用的時候卻很少用到,或者在用到的時候去“重復發明輪子了”。作為一個經典的數據類型,棧理應是被絕大多數語言支持的(不知道PB怎樣)。所以在這里要樹立一下“重用輪子”的意識:
            C#的十進制轉二進制實現:
             1 class Class1
             2     {
             3         /// <summary>
             4         /// 應用程序的主入口點。
             5         /// </summary>
             6         [STAThread]
             7         static void Main(string[] args)
             8         {
             9             //
            10             // TODO: 在此處添加代碼以啟動應用程序
            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的十進制轉二進制實現:
             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     }
            通過比較,會發現C#不大有“棧”的感覺,JAVA和C++更貼近于《數據結構》中對于數據類型“棧”的操作的定義。另外支持模板或者范型的特點讓人用起來總會感覺十分舒服。在這里提醒自己:以后這三種語言有“棧”可用了!
            posted on 2007-06-11 22:11 littlegai 閱讀(197) 評論(0)  編輯 收藏 引用 所屬分類: 我的讀書筆記
            漂亮人妻被中出中文字幕久久| 国内精品久久久久久99| 成人a毛片久久免费播放| 91亚洲国产成人久久精品| 91久久精品视频| 久久影视国产亚洲| 日韩久久久久久中文人妻| 久久综合综合久久狠狠狠97色88| 国产成人久久久精品二区三区| 麻豆久久| 久久se精品一区精品二区| 久久久久亚洲AV无码专区网站| 99久久夜色精品国产网站| 久久精品国产99国产精品澳门 | 香蕉aa三级久久毛片| 国产亚洲美女精品久久久2020| 99久久99久久| 久久中文字幕人妻熟av女| 亚洲精品乱码久久久久久| 91精品国产高清久久久久久91| 性做久久久久久免费观看| 久久本道伊人久久| 伊人情人综合成人久久网小说| 国产精品青草久久久久婷婷 | 高清免费久久午夜精品| 欧美国产成人久久精品| 国产91久久综合| 久久成人精品视频| 少妇精品久久久一区二区三区| 伊人色综合久久天天网| 国产午夜精品久久久久九九| 久久国产精品一国产精品金尊| 久久这里都是精品| 亚洲精品tv久久久久| 久久精品国产只有精品2020| 久久久久99精品成人片直播| 久久人人添人人爽添人人片牛牛| 久久夜色精品国产亚洲av| 精品国产91久久久久久久a | 久久久久亚洲精品日久生情| 欧美久久久久久|