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在哪里呢  回復  更多評論
            


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


          網站導航:
           
          主站蜘蛛池模板: 高陵县| 新疆| 手机| 武定县| 饶阳县| 双桥区| 哈巴河县| 通道| 西和县| 唐海县| 玉屏| 宜兰县| 论坛| 九龙城区| 社旗县| 莱州市| 乌兰浩特市| 河南省| 东明县| 桐庐县| 海淀区| 永福县| 天台县| 台湾省| 嵊泗县| 定西市| 浦城县| 香格里拉县| 原阳县| 台东县| 郎溪县| 大理市| 抚顺县| 五莲县| 兴宁市| 会泽县| 若尔盖县| 疏附县| 平陆县| 阳谷县| 建德市|