相信自己!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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(
          "原始數(shù)據(jù)如下:");
                      
          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
                      
          {
                          
          //從左側(cè)找大于中間值的數(shù)
                          while ((array[i] < middle) && (i < right))
                          
          {
                              i
          ++;
                          }

                          
          //從右側(cè)找小于中間值的數(shù)
                          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}次排序的結(jié)果", 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 北極雪 閱讀(258) 評論(0)  編輯  收藏 所屬分類: c#

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 济宁市| 大名县| 桦川县| 苏尼特右旗| 天津市| 阳谷县| 静宁县| 怀柔区| 通海县| 莎车县| 正宁县| 修文县| 义马市| 交口县| 白沙| 鹤峰县| 南阳市| 岳普湖县| 新沂市| 察哈| 咸丰县| 鄂托克旗| 九寨沟县| 金平| 山东省| 兴文县| 长白| 克什克腾旗| 黄山市| 石门县| 横山县| 普洱| 高清| 观塘区| 昔阳县| 平罗县| 河北省| 洛扎县| 平乐县| 新邵县| 兰溪市|