相信自己!

            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 北極雪 閱讀(263) 評論(0)  編輯  收藏 所屬分類: c#

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


          網站導航:
           
          主站蜘蛛池模板: 新宁县| 桂东县| 开阳县| 马鞍山市| 阳原县| 深水埗区| 玉溪市| 广宁县| 泾阳县| 行唐县| 罗源县| 桃江县| 成都市| 乡城县| 皮山县| 玉屏| 达州市| 沙洋县| 洪江市| 长岭县| 望江县| 沙田区| 连南| 静乐县| 白银市| 若羌县| 昌宁县| 巢湖市| 巍山| 邹平县| 射洪县| 碌曲县| 邵阳市| 石楼县| 钟山县| 高碑店市| 达拉特旗| 安顺市| 修文县| 青河县| 花莲县|