자료구조와 알고리즘
-
프코전-자바편 1~2장자료구조와 알고리즘/알고리즘 2023. 3. 30. 21:31
1장 -코드를 짤 때 흔히하는 실수 코드를 짤 때 가독성과 역할을 충분히 고려하지 못하고 쌓아올리기 시작하면, 어느순간 코드를 수정하는 것 보다 갈아 엎는 것이 나을 때가 생긴다. 이러한 상황을 방지하기 위해서 코드를 작성할 때 가독성과 역할을 신경 쓰며 문제를 단계별로 나누어 해결해보자 -디버깅과 시행착오 줄이기 > 코드를 단계별로 작성하라 > 하나의 단계를 작성하고 검증하라 > 단계 검증이 실패하면, 실패한 단계에서 더 자세히 로그를 찍어보자 - 실습 -전화번호부 만들기 사용자가 입력한 전화번호를 가진 사람들을 전화번호부에서 검색하는 기능을 구현해보자 처음에는 입력과 검색 모든 과정을 한 번에 생각하면서 코드를 작성하려 할 것이다. 이는 가독성이 떨어지는 코드 작성의 시발점이다. 전화번호를 검색하는 ..
-
배열 기반 List (C and java)자료구조와 알고리즘/자료구조 2023. 3. 10. 16:46
자료구조의 첫 걸음인 배열기반 리스트를 구현해 보았다. 추상자료형(ADT) -구현하고자 하는 자료구조에 대해 구체적인 기능의 완성과정을 언급하지 않고, 순수하게 기능이 무엇인지를 나열 한 것을 가리켜 추상자료형 ADT라고 한다. 특정 자료형의 내부 구현은 정확하게 알지 못해도 활용할 수 있도록 명시하는 작업이라고 생각해 볼 수 있다. (마치 자바에서 인터페이스 혹은 추상 클래스를 정의하는 것과 비슷한 느낌이다.) 자료구조를 공부할 때 1. ADT를 정의하고 2. ADT를 근거로 자료구조를 활용하는 함수를 정의하고 3. ADT를 근거로 구현하는 과정 위 3단계 과정이 필요하다. 배열을 이용한 LIST 자료형의 구현 리스트는 간단하게 말해서 저장순서를 유지하고, 중복을 허용하여 자료를 저장하는 구조이다. 1..
-
재귀자료구조와 알고리즘/자료구조 2023. 3. 2. 10:05
1. 함수의 재귀적 호출 함수의 재귀적 호출이란, 함수 내에서 자기 자신을 다시 호출하는 것 간단하게 이해하는 방향은 하나의 함수는 원본이 있고, 재귀호출이 발생하면, 복사본이 만들어져서 호출한다고 생각해보자. 간단한 예제를 통한 재귀 호출의 흐름 Num 3으로 시작해서 조건 검사 -> true면 호출종료, false면 num=2로 recursive 재호출 -> 종료조건 만족 시, recursive (0) 반환 -> recursive(1)반환 -> recursive(3)반환 순서로 이어진다. *재귀함수는 탈출조건이 필요하다. * recursive호출을 기준으로 위 문장은 최종 반환 전 모든 함수가 반복하는 것, recursive 후는 탈출조건 만족 후 함수가 반환을 시작하면서 반복할 문장 예제2 팩토리얼..