kdgyun / Sorting_Algorithm

implementation for various sorting algorithm in java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool



Sorting Algorithm Project


Contents

Feature

  • 기본 정렬은 오름차순으로 정렬 됩니다.
    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



Directory structure


This repository is organized as follows:
/Sorting_Algorithm
	/SortingAlgorithm
		/Java
			/BubbleSort
			/HeapSort
			/ ...



[Preview subFolder] - 알파벳순

  • 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에 필요한 유틸 클래스입니다.



Build and Usage



How to Use (download ZIP) on Eclipse



  • 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);
	}
}




Natural ordering



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>() { ... };
}




Reverse ordering



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.






일부 구현 대한 내용은 블로그에 기재하고 있습니다.



    부분적으로 추가 구현 또는 차이가 있을 수 있습니다.