본문 바로가기
728x90
반응형

알고리즘4

recursion으로 미로찾기 미로찾기 package recursion; public class Maze { private static int N = 8; private static int[][] maze = { { 0, 0, 0, 0, 0, 0, 0, 1 }, { 0, 1, 1, 0, 1, 1, 0, 1 }, { 0, 0, 0, 1, 0, 0, 0, 1 }, { 0, 1, 0, 0, 1, 1, 0, 0 }, { 0, 1, 1, 1, 0, 0, 1, 1 }, { 0, 1, 0, 0, 0, 1, 0, 1 }, { 0, 0, 0, 1, 0, 0, 0, 1 }, { 0, 1, 1, 1, 0, 1, 0, 0 } }; private static final int PATHWAY_COLOR = 0; private static final int W.. 2020. 6. 23.
최댓값 구하는 알고리즘_java class Max3{ public static void main(String[] args){ Sanner stdIn = new Scanner(System.in); System.out.println("세정수의 최댓값을 구합니다"); System.out.print("a의 값"); int a = stdIn.nextInt(); System.out.print("b의 값"); int b = stdIn.nextInt(); System.out.print("c의 값"); int c = stdIn.nextInt(); int max = a; if(b> max) max=b; if(c>max) max=c; System.out.println("최댓값:"+max+); } } 최댓값 구하는 알고리즘. 2020. 6. 16.
recursion - 순차탐색, 이진트리탐색 명시적 설계 1) 순차 탐색 int search (int [] data, int begin, int end, int target){ if(begin > end){ return -1; }else if(target == data[begin]){ return begin; }else{ return search(data, begin+1, end, target); } } 2) 이진트리 탐색 public static int binarySearch(String[] items, String target, int begin, int end){ if(begin > end) return -1; else{ int middle = (begin+end)/2; int compResult = target.compareTo(items[.. 2020. 6. 9.
순환함수(재귀함수, Recursion) 순환함수, 재귀함수,Recursion Ex01 - 무한 루프 In java public class Recursion { public static void main(String[] args) { func(); } public static void func() { System.out.println("hello recursion"); func(); } } 실행 결과 Ex02 - 재귀함수 2 In java public class Recursion { public static void main(String[] args) { func(5); } public static void func(int k) { if(k 2020. 6. 4.
728x90
반응형