相信自己!

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            26 隨筆 :: 3 文章 :: 13 評論 :: 0 Trackbacks
          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          namespace ConsoleApplication2
          {
              
          class Program
              
          {
                  
          //int num = 0;
                  static void Main(string[] args)
                  
          {
                      Stack
          <string> aa = new Stack<string>();
                      aa.Push(
          "111");
                      aa.Push(
          "222");
                      aa.Push(
          "333");
                      
          //int num = aa.Count;
                      for (int i = 0; i < aa.Count; i++)
                      
          {
                          string bb 
          = aa.Pop();
                          Console.WriteLine(bb);
                      }

                      Console.Read();

                  }

                  
              }

          }






          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          namespace ConsoleApplication2
          {
              
          class Program
              
          {
                  
          //int num = 0;
                  static void Main(string[] args)
                  
          {
                      
          int[] ss = new int[] 12,3,67,22,89,102,2,54};
                      Console.WriteLine(
          "原始數據如下:");
                      
          for (int k = 0; k < ss.Length; k++)
                      
          {
                          Console.Write(ss[k] 
          + "    ");
                      }

                      Console.WriteLine(
          "  ");
                      sort(ss, 
          07,0);
                      
                      Console.Read();
                  }

                  
          public static void sort(int[] array, int left, int right,int num)
                  
          {
                      
                      
          int i, j;
                      
          int middle, t;
                      i 
          = left;
                      j 
          = right;
                      middle 
          = array[(left + right) / 2];
                      
          do
                      
          {
                          
          //從左側找大于中間值的數
                          while ((array[i] < middle) && (i < right))
                          
          {
                              i
          ++;
                          }

                          
          //從右側找小于中間值的數
                          while ((array[j] > middle) && (j > left))
                          
          {
                              j
          --;
                          }

                          
          //找到了一對就交換
                          if (i <= j)
                          
          {
                              t 
          = array[i];
                              array[i] 
          = array[j];
                              array[j] 
          = t;
                              i
          ++;
                              j
          --;
                              num 
          = num + 1;
                              Console.WriteLine(
          "第{0}次排序的結果", num);
                              
          for (int k = 0; k < array.Length; k++)
                              
          {
                                  Console.Write(array[k] 
          + "    ");
                              }

                              Console.WriteLine(
          "  ");
                          }

                      }
           while (i <= j); 
                      
          if (left < j)
                      
          {
                          sort(array, left, j,num);
                      }

                      
          if (right> i)
                      
          {
                          sort(array, i, right,num);
                      }

                  }

              }

          }
          posted on 2008-04-29 16:18 北極雪 閱讀(257) 評論(0)  編輯  收藏 所屬分類: c#

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 新郑市| 澄江县| 来凤县| 崇信县| 吉安县| 仙桃市| 陇西县| 鄯善县| 大厂| 汽车| 平谷区| 邢台县| 江孜县| 海阳市| 龙泉市| 股票| 安徽省| 遵义县| 苍南县| 沐川县| 南昌县| 凤冈县| 龙口市| 内江市| 阿合奇县| 钟祥市| 织金县| 宕昌县| 滦平县| 河西区| 邯郸县| 阿图什市| 修文县| 开原市| 伊春市| 慈溪市| 井陉县| 长葛市| 虹口区| 古交市| 咸阳市|