본문 바로가기

프로그래밍

(99)
이진탐색트리 검색 추가 삭제 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..
연결리스트를 이용한 다항식을 계산하고 사용자가 입력한 문자열을 파싱하는 Polynominal 코드 만들기 자료구조 수업에서 연결리스트를 이용한 다항식 계산 프로그램을 작성하라는 과제를 받았다. https://youtu.be/UviSUv21iB8 여기 유튜브에서 하는것과 비슷하게 만들면 될듯하다 기능 1. f = 5x 같은 문자열을 입력하면 f라는 Poly 클래스를 만들고 5x Term 클래스를 만들어 Poly에 연결한다. 2. f = 6x + 7x^2 같은 문자열을 한번 더입력하면 f 자리에 6x + 7x^2을 넣는다. 3. print f를 입력하면 f 함수를 출력한다. 4. calc f 2를 입력하면 f함수에 따른 2를 계산한 결과를 출력한다. 5. f = f + g를 입력하면 함수 f와 g를 계산한 함수를 저장한다. 연결리스트를 이용하여 메모리가 가능한 한도내에 무제한으로 저장할 수 있도록 만든다. 자바..
선형덱 #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..
이것이 자바다 11장 확인 문제 답 - 신용권의 Java 프로그래밍 정복 Object 클래스에 대한 설명 중 틀린 것은 무엇입니까? 4번 괄호 안을 채워보세요 hashCode(), equals() 해시코드를 리턴하세요 public class Student { private String studentNum; public Student(String studentNum) { this.studentNum = studentNum; } public String getStudentNum() { return studentNum; } @Override public boolean equals(Object obj) { if(obj instanceof Student) { Student student = (Student) obj; if(studentNum.equals(student.getStuden..
연결리스트 스택 #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)..