본문 바로가기

프로그래밍/C, C++

(19)
이진탐색트리 검색 추가 삭제 TNode* search(TNode* n, int key) { if (n == NULL) return NULL; else if (key == n->data) return n; else if (key data) return search(n->left, key); else return search(n->right, key); } int insert(TNode* r, TNode* n) { if (n->data == r->data) return 0; else if (n->data data) { if (r->left == NULL) r->left = n; else insert(r->left, n); } else { if (r->right == NULL) r->right = n; else inse..
두근두근 자료구조 8장 연습문제 1. 다음 트리에 대한 중위 순회 결과는? 4 2. 다음 트리를 전위 순회로 운행할경우 다섯 번째로 탐색되는 것은? 2 3. 다음 그림과 같은 이진트리를 후위 순회한 결과는? 4 4. 다음 트리에서 단말 노드 수는? 3 5. 다음 그림에서 트리의 차수는? 1 6. 메모리상에 배열로 저장할 때 가장 낭비가 큰 트리는? 1 7. 다음 중 같은 개수의 노드가 저장되는 경우, 가장 높이가 작아지는 트리는? 3 8. 다음 그림에서 트리의 차수와 단말 노드의 개수는? 2 9. 이진 트리에서 높이가 5일 때, 이 트리는 최대 몇 개의 노드를 가질 수 있는가? 4 10. 다음의 이진트리에 대하여 다음 질문에 답하여라. (1) 위의 트리를 1차원 배열로 표현하라. (2) 위의 트리를 전위 순회한 결과를 써라. 6, 4,..
이진트리 #include #include typedef struct BinTrNode { char data; struct BinTrNode* left; struct BinTrNode* right; } TNode; typedef struct LinkedNode { TNode* data; struct LinkedNode* link; } Node_q; Node_q* front = NULL; Node_q* rear = NULL; int is_empty() { return front == NULL; } void init_queue() { front = rear = NULL; } int size() { Node_q* p; int count = 0; for (p = front; p != NULL; p = p->link) co..
선형덱 #include #include #define MAX_QUEUE_SIZE 100 int data[MAX_QUEUE_SIZE]; int front; int rear; void init_queue() { front = rear = 0; } void add_rear(int val) { enqueue(val); } int delete_front() { return dequeue(); } int get_front() { return peek(); } int is_empty() { return front == rear; } int is_full() { return front == (rear + 1) % MAX_QUEUE_SIZE; } int size() { return (rear - front + MAX_QUEUE..
연결된큐 #include #include #define MAX_QUEUE_SIZE 100 typedef struct LinkedNode { int data; struct LinkedNode* link; } Node; Node* front = NULL; Node* rear = NULL; void init_queue() { front = rear = NULL; } int is_empty() { return front == NULL; } int size() { Node* p; int count = 0; for (p = front; p != NULL; p = p->link) count++; return count; } void enqueue(int val) { Node* p = (Node*)malloc(sizeof(No..
연결리스트 스택 #define _CRT_SECURE_NO_WARNINGS #include #include typedef int Element; typedef struct { Element data; Node* link; }Node; Node* top = NULL; void error(const char str[]) { printf("%s\n", str); exit(1); } void init_stak() { top = NULL; } int is_empty() { return top == NULL; } int size() { Node* p; int count = 0; for (p = top; p != NULL; p = p->link) { count++; } return count; } void push(Element e)..
배열 스택 #include #include #define MAX_STACK_SIZE 100 typedef int Element; Element data[MAX_STACK_SIZE]; int top; void error(const char str[]) { printf("%s\n", str); exit(1); } void init_stak() { top = -1; } int is_empty() { return top == -1; } int is_full() { return top == MAX_STACK_SIZE - 1; } int size() { return top + 1; } void push(Element e) { if (is_full) error("스택 포화 에러"); data[++top] = e; } Eleme..
[c/c++] Mirth 콘솔 게임 리듬게임 만들기 c/c++ 프로그래밍 언어를 이용하여 콘솔 화면에서 동작하는 리듬게임을 만들었습니다. fmod 라이브러리를 사용합니다. https://github.com/wndudwkd003/Cpp_Console_Rythm_Game.git GitHub - wndudwkd003/Cpp_Console_Rythm_Game: C++ 수업 과제, 콘솔 게임 만들기 C++ 수업 과제, 콘솔 게임 만들기. Contribute to wndudwkd003/Cpp_Console_Rythm_Game development by creating an account on GitHub. github.com https://drive.google.com/file/d/1a2BvLjBVRvBdLhP5i1mbCCTzLehvQAZ_/view?usp=shar..