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

          評論

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


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


          網站導航:
           
          主站蜘蛛池模板: 邛崃市| 阿鲁科尔沁旗| 无棣县| 贵州省| 明星| 阜南县| 宝鸡市| 孝昌县| 芦溪县| 澳门| 杭州市| 英德市| 天长市| 东宁县| 昭通市| 龙游县| 墨江| 宝丰县| 蒙自县| 麻阳| 平南县| 永济市| 呼和浩特市| 南投市| 阿克| 同仁县| 清苑县| 盖州市| 鄂托克前旗| 河源市| 宜宾县| 桐柏县| 临沂市| 锡林浩特市| 荣成市| 出国| 博白县| 漳平市| 霍城县| 赤壁市| 高邑县|