BlogJava 聯系 聚合 管理  

          Blog Stats

          隨筆檔案

          exams


          java世界

          世界Java

          插入排序:

            package org.rut.util.algorithm.support;
            import org.rut.util.algorithm.SortUtil;
            /**
            * @author treeroot
                  @since  310-301
            * @version  920-533 
                  **/
             public class InsertSort implements SortUtil.Sort
            {
             /* (non-Javadoc)
             * @see org.rut.util.algorithm.SortUtil.Sort#sort(int[])
             */
             public void sort(int[] data)
             {
              int temp;
              for(int i=1;i for(int j=i;(j>0)&&(data[j] SortUtil.swap(data,j,j-1);
             }
            }

            冒泡排序:

            package org.rut.util.algorithm.support;
            import org.rut.util.algorithm.SortUtil;
            /**
            * @author treeroot
            * @since 2006-2-2
            * @version 1.0
            */
            public class BubbleSort implements SortUtil.Sort
            {
             /* (non-Javadoc)
             * @see org.rut.util.algorithm.SortUtil.Sort#sort(int[])
             */
             public void sort(int[] data)
             {
              int temp;
              for(int i=0;i for(int j=data.length-1;j>i;j--)
              {
               if(data[j] SortUtil.swap(data,j,j-1);
              }
             }
            }

            選擇排序:

            package org.rut.util.algorithm.support;
            import org.rut.util.algorithm.SortUtil;
            /**
            * @author treeroot
            * @since 2006-2-2
            * @version 1.0
            */
            public class SelectionSort implements SortUtil.Sort
            {
             /*
             * (non-Javadoc)
             *
             * @see org.rut.util.algorithm.SortUtil.Sort#sort(int[])
             */
             public void sort(int[] data)
             {
              int temp;
              for (int i = 0; i < data.length; i++)
              {
               int lowIndex = i;
               for (int j = data.length - 1; j >i; j--)
               {
                if (data[j] < data[lowIndex])
                {
                 lowIndex = j;
                }
               }
               SortUtil.swap(data,i,lowIndex);
              }
             }
            }
          posted on 2007-09-11 15:02 java2java 閱讀(749) 評論(1)  編輯  收藏

          評論

          # re: 用Java實現幾種常見的排序算法 2007-09-12 20:01 千里冰封
          SortUtil在哪里呢  回復  更多評論
            


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


          網站導航:
           
          主站蜘蛛池模板: 泰和县| 晴隆县| 渝北区| 丰镇市| 洛南县| 虎林市| 紫金县| 日土县| 台湾省| 山丹县| 洛南县| 都兰县| 房产| 昭觉县| 武隆县| 天长市| 峨边| 四川省| 高唐县| 女性| 新津县| 宿松县| 靖远县| 仪征市| 武威市| 滨海县| 桐梓县| 台东县| 阿尔山市| 大渡口区| 安平县| 新建县| 年辖:市辖区| 景德镇市| 泸定县| 尼木县| 都兰县| 马公市| 屯门区| 咸阳市| 兴安县|