• <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年12月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            常用鏈接

            留言簿(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 閱讀(206) 評論(0)  編輯 收藏 引用 所屬分類: 我的讀書筆記
            国产毛片久久久久久国产毛片| 久久精品视频一| 久久免费香蕉视频| 囯产精品久久久久久久久蜜桃 | 久久er国产精品免费观看8| 久久精品无码专区免费| 久久亚洲美女精品国产精品| 国产精品VIDEOSSEX久久发布| 久久狠狠爱亚洲综合影院| 久久久久久综合一区中文字幕 | 亚洲精品午夜国产VA久久成人| 久久精品国产只有精品2020| 久久99热这里只有精品66| 亚洲精品国产成人99久久| 色88久久久久高潮综合影院| 久久男人AV资源网站| 青青草国产成人久久91网| 久久亚洲精精品中文字幕| 亚洲精品午夜国产va久久| 韩国三级中文字幕hd久久精品| 伊人色综合久久天天网| 狠狠色综合网站久久久久久久| 99久久99这里只有免费费精品| 国产精品中文久久久久久久| 久久久久亚洲AV综合波多野结衣 | 久久综合久久美利坚合众国| 国产精品美女久久久免费| 久久久久久久99精品免费观看| 精品无码久久久久久午夜| 久久香蕉国产线看观看精品yw| 色欲久久久天天天综合网精品 | 久久午夜无码鲁丝片秋霞| 无码任你躁久久久久久| 久久精品国产精品亚洲| 精品国产青草久久久久福利| 久久久免费观成人影院| 久久国产美女免费观看精品| 久久99久久无码毛片一区二区| 日本精品一区二区久久久| 亚洲国产精品无码久久久久久曰| 欧美亚洲日本久久精品|