전체 글 102

이진 탐색 트리(Binary Search Tree)

이진 탐색 트리(Binary Search Tree)각 노드에는 값이 존재각 노드의 왼쪽 서브트리에는 그 노드의 값보다 작은 값을 지닌 노드들로 이루어 짐.각 노드의 오른쪽 서브트리에는 그 노드의 값보다 큰 값을 지닌 노드들로 이루어 짐. 노드 클래스class Node { public: int data; Node* left; Node* right; ​ Node(int data) { this->data = data; left = NULL; right = NULL; } }; BST 클래스​class BinarySearchTree { public: Node* root; ​ BinarySearchTree(int data) { root = new Node(data); } ​ void Insert(int data);..

아카이빙 2018.05.29

하노이 타워 문제

하노이 타워 문제너무 유명한 문제이기 때문에 문제는 생략.재귀를 이용할 수 있는지를 알아보는 문제. #include ​ void Move(int id, char from, char to) { printf("[원판%d] %c -> %c\n",id, from, to); } ​ //from에 꽂혀있는 num개의 원판을 by를 거쳐서 to로 이동. void SolveHanoi(int num, char from, char by, char to) { if (num == 1) { Move(1, from, to); return; } ​ SolveHanoi(num - 1, from, to, by); Move(num, from, to); SolveHanoi(num - 1, by, from, to); } ​ int main..

아카이빙 2018.05.29

struct와 class 차이

struct와 class 차이c++에서 struct와 class는 무슨 차이가 있을까?class는 객체지향적으로, 멤버 변수에 대한 접근 권한을 설정할 수 있고, 생성자, 메소드를 추가할 수 있고, 상속도 되지만 struct는 안된다!그런 줄 알았는데 아니었다. struct에서도 다 된다. (C++) struct#include #include ​ using namespace std; ​ struct Sample { private: int val; public: Sample() { val = 9; } ​ void Print() { cout

아카이빙/C, C++ 2018.05.27

string과 character 배열

string과 character 배열stringstring은 c++의 built-int 데이터타입으로 하나의 클래스이다.string 클래스는 attributes, constructor, functions을 갖는다.s1, s2, s3은 string 클래스의 인스턴스string s1 = "Hello"; string s2("World!"); string s3; s3 = "This is a string";character 배열character 배열은 char 타입의 배열마지막은 항상 '\0'으로 끝난다.char s1[] = "Hello"; char s2[] = {'W', 'o', 'l', 'r', 'd', '!', '\0'}; string vs character 배열인덱싱에서 string은 charAt 함수를 ..

아카이빙/C, C++ 2018.05.26