Sort(countingSort, radixSort) public void bestRadixSort(int[] data) { int digit = 0; for (int i = 0; i digit) { digit = length; } } for (int i = 0; i 프로그래밍/알고리즘 2017.02.24
다익스트라(Dijkstra Algorithm) class GraphDijkstra { final int INFINITY = 60000; private int[][] adjMat; private Vertex[] vertices; private int[] distance; private int numVertices; public GraphDijkstra(int max) { adjMat = new int[max][max]; vertices = new Vertex[max]; distance = new int[max]; numVertices = 0; for (int i = 0; i 프로그래밍/알고리즘 2017.02.24
DFS(미로찾기) class Graph { private int[][] adjMat; private Vertex[] vertices; private int numVertices; public Graph(int max) { adjMat = new int[max][max]; vertices = new Vertex[max]; numVertices = 0; for (int i = 0; i 프로그래밍/알고리즘 2017.02.24
이진트리(BinaryTree) public class BinaryTree { private TreeNode root; //순회 travers : (preOrder) public void preOrder(TreeNode tempNode) { if (tempNode != null) { tempNode.showNode(); preOrder(tempNode.leftNode); preOrder(tempNode.rightNode); } } //순회 travers : (inorder) public void inorder(TreeNode tempNode) { if (tempNode != null) { inorder(tempNode.leftNode); tempNode.showNode(); inorder(tempNode.rightNode); } } /.. 프로그래밍/알고리즘 2017.02.24
quickSort public void testQuickSort() { List numberList = Arrays.asList(1, 3, -5, -9, 10, 7, 4, 0, 9, 22); List quickResult = quickSort(numberList); for (int i = 0; i 프로그래밍/알고리즘 2017.02.24
Queue public class Queue { private QueueNode front; private QueueNode rear; public Queue() { front = null; rear = null; } public void insert(int value) { QueueNode newNode = new QueueNode(); newNode.value = value; if (isEmpty()) { front = newNode; rear = newNode; } else { rear.link = newNode; rear = newNode; } } public boolean remove() { if (isEmpty()) { return false; } else { front.link = front; if (.. 프로그래밍/알고리즘 2017.02.24
binarySearch public boolean binarySearch(List numbers, int value) { if (numbers == null || numbers.isEmpty()) { return false; } int comparison = numbers.get(numbers.size() / 2); if (value == comparison) { //success return true; } if (value 프로그래밍/알고리즘 2017.02.24
Stack(TwoStack) public class TwoStack { public static int TYPE_TOP_1 = 0; public static int TYPE_TOP_2 = 1; private StackNode top1, top2; public TwoStack() { top1 = null; //top1 초기화(공백 상태의 스택 top2 = null; //top2 초기화(공백 상태의 스택 } public void push(int type, int value) { //스택의 top에 자료 삽입 StackNode newNode = new StackNode(); //새 노드 생성 newNode.value = value; if (type == TYPE_TOP_1) { newNode.nextLink = top1; //새 노드가 .. 프로그래밍/알고리즘 2017.02.24
Stack(getMin) public class ListStack { private StackNode top; //스택의 top public ListStack() { top = null; //top 초기화(공백 상태의 스택 } public void push(int item) { //스택의 top에 자료 삽입 if (isEmpty()) top = new StackNode(item); else { StackNode newNode = new StackNode(item); //새 노드 생성 if (newNode.min > top.min) newNode.min = top.min; newNode.nextLink = top; //새 노드가 top이 가리키던 노드를 가리키도록 함 top = newNode; //top이 새 노드를 가리키도록 변.. 프로그래밍/알고리즘 2017.02.24
문자열 rotate 체크 public boolean checkRotate(String targetStr, String checkStr) { if (targetStr.length() != checkStr.length()) { return false; } char[] oldChar = targetStr.toCharArray(); char[] checkChar = checkStr.toCharArray(); String result = new String(); int index = 0; for (int i = 0; i 프로그래밍/알고리즘 2017.02.24