This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void radixSort(int[] arr) { | |
int[] result = arr ; | |
for (int place = 1; place <= 1000000000; place *= 10) { | |
result = countingSort(result, place); | |
} | |
for (int i = 0; i < arr.length; i++) { | |
arr[i] = result[i]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bucketSort(int[] a, int maxVal) { | |
int [] bucket=new int[maxVal+1]; | |
for (int i=0; i<bucket.length; i++) { | |
bucket[i]=0; | |
} | |
for (int i=0; i<a.length; i++) { | |
bucket[a[i]]++; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* node์ childe node๋ฅผ ๋น๊ตํ์ฌ ํํํํฉ๋๋ค. | |
* @param arr | |
* @param nodeIndex ํํํํ node ์ ๋ฒํธ์ ๋๋ค. | |
* @param heapSize ์์ ์ด์ง ํธ๋ฆฌ์ ํฌ๊ธฐ์ ๋๋ค. | |
*/ | |
void heapify(int[] arr, int nodeIndex, int heapSize) { | |
int ai = arr[nodeIndex]; | |
while (nodeIndex < heapSize/2) { // arr[i] ๋ leaf ๊ฐ ์๋๊ฒฝ์ฐ๋ง loop ๋ฅผ ์ํํฉ๋๋ค. | |
int j = 2 * nodeIndex + 1; // j๋ ai์ ์ข์ธก ์์ ๋ ธ๋์ index ์ ๋๋ค. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* heapify ํจ์๋ฅผ ํ์ฉํ์ฌ Heap ์ ๊ตฌ์ถํฉ๋๋ค. | |
* @param arr | |
* @param nodeIndex | |
* @param heapSize | |
*/ | |
void buildHeap(int[] arr, int nodeIndex, int heapSize) { | |
if(nodeIndex >= heapSize/2) return; | |
buildHeap(arr, 2 * nodeIndex + 1, heapSize); // buildHeap- left subTree | |
buildHeap(arr, 2 * nodeIndex + 2, heapSize); // buildHeap- right subTree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomString implements Comparable<CustomString> { | |
public String str; | |
public CustomString(String str) { | |
this.str = str; | |
} | |
public int compareTo(CustomString cs) { | |
int leng1 = this.str.length(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
import java.util.PriorityQueue; | |
public class Test | |
{ | |
public static void main(String[] args) | |
{ | |
Comparator<String> comparator = new StringLengthComparator(); | |
PriorityQueue<String> queue = | |
new PriorityQueue<String>(10, comparator); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BinarySearchTree { | |
public static Node root; | |
public BinarySearchTree() { | |
this.root = null; | |
} | |
/** | |
* tree ์์ key ๋ก node ๋ฅผ ํ์ํฉ๋๋ค. | |
* @param id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <math.h> | |
using namespace std; | |
int main() { | |
int a[7] = {0,500,300,200,50,30,10}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
String n = sc.next(); | |
char[] arrChar = n.toCharArray(); | |
for (int i = 0; i < arrChar.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package programers; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class StringZip { | |
public int solution2(String s) { | |
int minResult = s.length(); | |
for (int unit = 1; unit <= s.length() / 2; unit++) { // for #01 | |
int resultLength = unit; |