본문 바로가기

분류 전체보기167

[그래픽스] line.cpp 만들기 vec.h #pragma once #include #include #define M_PI 3.14159265358979323846 #define radians(x) x*M_PI/180.0 #define degrees(x) x*180.0/M_PI ////////////////////////////////////////////////////////////////////////////// // // 2D vector // ///////////////////////////////////////////////////////////////////////////// class vector2D { float x; float y; public: // // --- Constructors and Destructors ---.. 2022. 1. 28.
[알고리즘] Assignment 5 - LCS 알고리즘, BFS 알고리즘, Kruskal 알고리즘, Dijkstra 알고리즘, Prim 알고리즘 1. LCS (Longest Common Subsequence, 최장 공통 부분 문자열) #include #define MAX(a,b) ((a)>(b)? (a):(b)) int LCS_table[10][10] = { 0, }; void LCS_length(int str1_len, int str2_len, char* str1, char* str2) { for (int i = 1; i < str1_len; i++) { for (int j = 1; j < str2_len; j++) { if (str1[i] == str2[j]) { LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1; } else { LCS_table[i][j] = MAX(LCS_table[i - 1][j], LC.. 2022. 1. 28.
[알고리즘] Assignment 4 Implement the following algorithms in the C programming language and put the described input to the algorithm in order to check the answer. Submit 1) a report containing outputs of the following problems and 2) the codes you have written (screenshots okay). 1. Implement an algorithm of Fibonacci numbers using dynamic programming and get the answers when feeding 𝑛=5 and 𝑛=10 into the algorithm as.. 2022. 1. 28.
[알고리즘] Assignment 3 - 정렬 알고리즘 (bubble sort, insertion sort, merge sort, quick sort, radix sort, bucket sort) 1. Code #include #include #define SIZE 1000 #define DIGIT 4 int origin[SIZE], result[SIZE], result_2[SIZE]; void bubble_sort() { int i, j, temp; for (i = SIZE - 1; i > 0; i--) { for (j = 0; j origin[j + 1]) { temp = origin[j]; origin[j] = origin[j + 1]; origin[j + 1] = temp; } } } } void insertion_sort() { int i, j, temp; for (i = 1; i < SIZE; i++) { temp = origin[i];.. 2022. 1. 28.
[알고리즘] Assignment 2 Submit a word, hwp or pdf file to the e-class that contains (1) your answers for the following exercises, and (2) your codes written in the C programming language and their results for programming exercises (screenshots okay). 1. (programming) Write a program that takes a number n and displays the largest k satisfying the following equations: 2^k 2022. 1. 28.
[알고리즘] Assignment 1 2022. 1. 28.
[자료구조 프로그래밍 연습문제] 이진탐색트리 (binary search tree), 힙 (heap), min cost spanning tree, 전위표기식 (postfix), 연결 리스트 (linked list) 1. binary search tree와 heap binary search tree는 노드에 key 값만 저장하는 것이 아니라 key값과 관련된 정보(associated item)를 같이 저장한다. 후자를 단순히 value라고 하자. 이 (key, value) 쌍을 보통 dictionary pair라고 부른다 (교재 ADT 5.3 Dictionary 참조). 은 binary search tree의 예로 각 노드에 키 값만 나타낸 것이다. 는 각 노드에 (key, value) 쌍을 나타낸 것이다. (앞의 한자리 수는 key, 뒤의 두자리 수가 value) complete binary tree로 표현되는 heap도 노드에 (key, value) 쌍을 저장할 수 있다. (교재 5.6.3절에는 heap의 노드에.. 2022. 1. 28.
[자료구조 프로그래밍 연습문제] 힙 정렬 (heap sort) heap sort A. 배열 a[1]에서 a[11]에 11개의 999보다 큰 네자리 이상의 양의 정수가 저장되어 있다고 하자. 교재 Program 7.13: Heap sort의 함수 heapSort를 호출하여 이들을 오름순으로 정렬하는 과정을 확인하고자 한다. 이를 위해 Program 7.13에서 함수 adjust가 호출될 때마다 그 호출 직후 시점의 배열 a[1] 부터 a[11] 까지의 값을 출력하시오. 또한 정렬 진행 과정 설명을 위해 자신이 확인하고 싶은 기타 변수 값이 있으면 출력하시오. 출력된 값을 보고 배열을 complete binary tree로 그림을 그려서 해당 adjust의 수행 결과와 정렬 진행 과정에 대해 설명하시오. (complete binary tree 그림은 육필로 그려도 되고.. 2022. 1. 28.
[자료구조 프로그래밍 연습문제] 연결 리스트 (linked list) invert 함수, 원형 연결 리스트 (circular linked list) linked list A. 교재 4.5절에 설명된 Program 4.16: Inverting a singly linked list의 함수 invert를 고려하자. 리스트 p가 있을 때 q = invert(p); 를 호출하면 처럼 리스트의 링크가 방향이 바뀐다. 교재의 invert를 수행하면서 그 동작과정을 확인하기 위한 프로그램을 아래와 같이 작성하고 invert의 실행 과정을 확인 및 설명하시오. main 함수에서 노드 2개로 구성된 리스트 L2를 생성한 후, 생성한 리스트를 출력한다 (각 노드의 주소, 데이터 필드 값, link 필드 값을 출력한다.) 생성한 리스트에 대해 invert 함수를 호출한다. invert에서 while loop이 매회 수행된 직후마다 다음 회를 수행하기 전에 변수 trail.. 2022. 1. 12.