Skip to content

kdgyun/Sorting_Algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

103 Commits
Β 
Β 
Β 
Β 

Repository files navigation



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.






일뢀 κ΅¬ν˜„ λŒ€ν•œ λ‚΄μš©μ€ λΈ”λ‘œκ·Έμ— κΈ°μž¬ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.



Β Β Β  λΆ€λΆ„μ μœΌλ‘œ μΆ”κ°€ κ΅¬ν˜„ λ˜λŠ” 차이가 μžˆμ„ 수 μžˆμŠ΅λ‹ˆλ‹€.