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 閱讀(748) 評論(1)  編輯  收藏

          評論

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


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


          網站導航:
           
          主站蜘蛛池模板: 二连浩特市| 宁强县| 灌云县| 陕西省| 瑞丽市| 余干县| 收藏| 灌南县| 镇平县| 疏附县| 体育| 舒兰市| 海城市| 乌拉特后旗| 镇平县| 金寨县| 霍邱县| 海林市| 晋中市| 唐海县| 浪卡子县| 武鸣县| 法库县| 吉木乃县| 嘉禾县| 乡宁县| 黄梅县| 东海县| 九龙县| 本溪市| 梧州市| 桃园县| 来安县| 松滋市| 伊通| 西盟| 闻喜县| 闸北区| 新沂市| 周宁县| 金寨县|