-
κΈ°λ³Έ μ λ ¬μ μ€λ¦μ°¨μμΌλ‘ μ λ ¬ λ©λλ€.
Sorts the specified array into ascending order (natural order). -
λλΆλΆμ μ λ ¬ μκ³ λ¦¬μ¦μ κ°μ²΄ μ λ ¬μ μ§μν©λλ€.
Most sorting algorithms supports sorting objects. -
λ΄λ¦Όμ°¨μ μ λ ¬μ μ§μν©λλ€.
Supports sorting Descending order (reverse order).
See : Reverse ordering -
μΌλΆ μ λ ¬ μκ³ λ¦¬μ¦λ€μ μ€λ λλ₯Ό μ΄μ©ν λ³λ ¬ μ λ ¬μ μ§μν©λλ€. (μ§μνλ μ λ ¬ μκ³ λ¦¬μ¦)
Some sorting algorithms support parallel sorting using threads. (Supported Sorting Algoriths) -
μ¬μ©μ κ°μ²΄(ν΄λμ€)λ₯Ό μ λ ¬νλ κ²½μ° Comparator λλ Comparableμ μν λΉκ΅λ°©μμ λ°λμ ꡬνν΄μ£Όμ΄μΌ ν©λλ€.
if you want to sort specified array of objects, All elements in the array must implement the Comparable or Comparator interface. -
λ§μ½ ν΅ μ λ ¬μ μ¬μ©νκ³ μ νλ κ²½μ° μ°Έκ³ ν΄μ£ΌμκΈ° λ°λλλ€. Quick Sort info
if you use quick sort, Please note that Quick Sort info
This repository is organized as follows:
/Sorting_Algorithm
/SortingAlgorithm
/Java
/BubbleSort
/HeapSort
/ ...
- BinaryInsertionSort : Binary Insertion sort(μ΄μ§ μ½μ μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- BitonicSort : Bitonic sort(λ°μ΄ν λ μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- BubbleSort : Bubble sort(κ±°ν μ λ ¬)μ ꡬνν μμ€μ½λκ° μμ΅λλ€.
- CocktailSort : Cocktail sort(μΉ΅ν μΌ μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- CombSort : Comb sort(λΉ μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- CycleSort : Cycle sort(μν μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- DualPivotQuickSort : Dual Pivot Quick sort(μ΄μ€ νΌλ² ν΅ μ λ ¬)μ ꡬνν μμ€μ½λκ° μμ΅λλ€.
- HeapSort : Heap sort(ν μ λ ¬)μ ꡬνν μμ€μ½λκ° μμ΅λλ€.
- InsertionSort : Insertion sort(μ½μ μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- IntroSort : Intro sort(μΈνΈλ‘ μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- OddEvenMergeSort : Odd Even Merge Sort(νμ§ λ³ν© μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- OddEvenSort : Odd Even Sort(νμ§ μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- MergeSort : Merge sort(ν©λ³/λ³ν© μ λ ¬)μ ꡬνν μμ€μ½λκ° μμ΅λλ€.
- ParallelSort : μ€λ λλ₯Ό μ΄μ©ν λ³λ ¬ μ λ ¬μ ꡬνν μμ€μ½λκ° μμ΅λλ€.
- QuickSort : Quick sort(ν΅ μ λ ¬)μ ꡬνν μμ€μ½λκ° μμ΅λλ€.
- SelectionSort : Selection sort(μ ν μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- ShellSort : Shell sort(μ Έ μ λ ¬)μ ꡬνν μμ€μ½λκ° μμ΅λλ€.
- TimSort : Tim sort(ν μ λ ¬)λ₯Ό ꡬνν μμ€μ½λκ° μμ΅λλ€.
- Utils : reverse orderingμ νμν μ νΈ ν΄λμ€μ λλ€.
- 1. Project import
Window -> File -> New -> Java Project -> uncheck the "Use default location" and Browse the SortingAlgorithm folder -> Finish
- 2. Build path
Your Project -> Build Path -> Configure Build Path -> Project -> select the class path -> add -> Select SortingAlgorithm -> Apply and Close
- 3. import class
import [sorting algorithm package name].[sorting algorithm name];
using sorting method (All sorting methods are static methods).
//ex.
import BubbleSort.BubbleSort;
class YourClass {
public static void main {
int[] a = {1, 5, 2, 4};
BubbleSort.sort(a);
}
}If you want to sort an array of primitive types in natural order, use it as in the following example.
//ex. primitive type
import BubbleSort.BubbleSort;
class Main {
public static void main {
double[] a = {1.3, 5.2, 2.4231, 4.425};
BubbleSort.sort(a);
}
}If you want to sort an array of Wrapper or class object types in natural order, use it as in the following example.
//ex. Wrapper type
import BubbleSort.BubbleSort;
class Main {
public static void main {
Integer[] a = {1, 5, 2, 4};
BubbleSort.sort(a);
}
}//ex. class Object type
//class must implement the Comparable or Comparator interface.
import BubbleSort.BubbleSort;
class Custom {
...
}
class Main {
public static void main {
Custom[] a = new Custom[size];
BubbleSort.sort(a); // using Comparable
BubbleSort.sort(a, comp); // using Comparator
}
static Comparator<Custom> comp = new Comparator<Custom>() { ... };
}
If you want to sort an array of primitive types in reverse order, use it as in the following example.
//ex.
import BubbleSort.BubbleSort;
class YourClass {
public static void main {
int[] a = {1, 5, 2, 4};
// true : reverse order, false : natural order
BubbleSort.sort(a, true);
}
}
If you want to sort an array of Wrapper or class object types in reverse order, use it as in the following example.
//ex.
import BubbleSort.BubbleSort;
import Utils.Order;
class Main {
public static void main {
Integer[] a = {1, 5, 2, 4};
BubbleSort.sort(a, Order.reverseOrder());
// or Collections.reverseOrder() (in java.util package)
}
}Note : reverseOrder() method of Comparator Interface in Utils.Order returns a comparator that imposes the reverse ordering of this comparator.
Β Β Β λΆλΆμ μΌλ‘ μΆκ° ꡬν λλ μ°¨μ΄κ° μμ μ μμ΅λλ€.