⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortutil.java

📁 java实现的各种排序算法:插入排序、起泡排序、希尔排序等。
💻 JAVA
字号:
package org.rut.util.algorithm.support; 

//import org.rut.util.algorithm.support.MergeSort; 
//import org.rut.util.algorithm.support.QuickSort; 

/** 
* @author treeroot 
* @since 2006-2-2 
* @version 1.0 
*/ 
public class SortUtil { 
   public final static int INSERT = 1; 
   public final static int BUBBLE = 2; 
   public final static int SELECTION = 3; 
   public final static int SHELL = 4; 
   public final static int QUICK = 5; 
   public final static int IMPROVED_QUICK = 6; 
   public final static int MERGE = 7; 
   public final static int IMPROVED_MERGE = 8; 
   public final static int HEAP = 9; 

   public static void sort(int[] data) { 
       sort(data, IMPROVED_QUICK); 
   } 
   private static String[] name={ 
           "insert", "bubble", "selection", "shell", "quick", "improved_quick", "merge", "improved_merge", "heap" 
   }; 
    
   private static Sort[] impl=new Sort[]{ 
           new InsertSort(), 
           new BubbleSort(), 
           new SelectionSort(), 
           new ShellSort(), 
//           new QuickSort(), 
           new ImprovedQuickSort(), 
//           new MergeSort(), 
           new ImprovedMergeSort(), 
           new HeapSort() 
   }; 

   public static String toString(int algorithm){ 
       return name[algorithm-1]; 
   } 
    
   public static void sort(int[] data, int algorithm) { 
       impl[algorithm-1].sort(data); 
   } 

   public static interface Sort { 
       public void sort(int[] data); 
   } 

   public static void swap(int[] data, int i, int j) { 
       int temp = data[i]; 
       data[i] = data[j]; 
       data[j] = temp; 
   } 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -