BlogJava 聯(lián)系 聚合 管理  

          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實現(xiàn)幾種常見的排序算法 2007-09-12 20:01 千里冰封
          SortUtil在哪里呢  回復(fù)  更多評論
            


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 河北省| 石首市| 紫阳县| 临夏市| 平湖市| 柘城县| 清远市| 北海市| 浏阳市| 渑池县| 晴隆县| 鲁山县| 上高县| 葫芦岛市| 太仆寺旗| 香格里拉县| 枣强县| 合作市| 云霄县| 北辰区| 沾益县| 汉沽区| 曲松县| 开鲁县| 城口县| 邯郸市| 资溪县| 遂平县| 两当县| 南和县| 攀枝花市| 高雄县| 二连浩特市| 澎湖县| 沙湾县| 精河县| 辰溪县| 屯昌县| 洛宁县| 瑞昌市| 体育|