C (9) 썸네일형 리스트형 자료구조/C) 연결리스트를 이용한 실습 문제 풀이 문제 소스코드 #include #include typedef struct node { int coef; int exp; struct node* next; } Node; Node* newNode(int c, int e) { Node* p = (Node*)malloc(sizeof(Node)); p->coef = c; p->exp = e; p->next = NULL; return p; } Node* appendTerm(Node *k, int c, int e) { //k는 마지막항 Node* t = newNode(c, e); Node* khead = newNode(NULL, NULL); khead->next = k; while ((khead->next) != NULL) { khead = khead->next; .. 연결리스트 자료구조를 이용해서 구현한 다항식 계산기 #include #include typedef struct node { int coef; int exp; struct node* next; } Node; Node* newNode(int c, int e) { Node* p = (Node*)malloc(sizeof(Node)); p->coef = c; p->exp = e; p->next = NULL; return p; } Node* appendTerm(Node* k, int c, int e) { Node* t = newNode(c, e); Node* khead = newNode(0, 0); khead->next = k; while ((khead->next) != NULL) { khead = khead->next; } khead->next = t; retur.. 자료구조/C) 이진탐색트리 BST 응용 문제 소스 코드 문제 이전에 설명한 방식대로 트리 정보와 탐색 정보가 주어졌을 때, 트리를 생성하고 탐색 도중 방문하는 노드의 번호를 차례로 출력하는 프로그램을 작성하시오. 입력 예시 1 9 ↦ 노드 개수 5 3 9 (preorder - VLR) 3 8 15 8 0 2 2 0 0 15 0 0 9 7 10 7 12 0 12 0 0 10 0 0 3 ↦ 탐색 횟수 RLL LL LR 출력 예시 1 (□는 공백) □5 9 7 12 ↦ 첫 번째 탐색 결과 □5 3 8 ↦ 두 번째 탐색 결과 □5 3 15 ↦ 두 번째 탐색 결과 소스코드 #define _CRT_SECURE_NO_WARNINGS #include #include typedef struct node { int data; struct node* left; struct no.. 자료구조/C) Tree 트리 구현 #define _CRT_SECURE_NO_WARNINGS #include #include #include typedef struct node { int data; struct node* left; struct node* right; } Node; typedef struct Tree { Node* root; }Tree; Node* initNode(int data) { Node* node = (Node*)malloc(sizeof(Node)); node->left = NULL; node->right = NULL; node->data = data; return node; } Tree* insertTree(Node* x, Node* y, Node* z, Tree* tr, int cnt) { Tree* subtr .. Socket Programming in C Client-Server 매커니즘 가정 : 서로 다른 네트워크 머신 (M1, M2) 가 상호 소통하는 프로그램을 만들고자 한다. 한 사람이 M1에서 첫번재 프로그램을 시작하면 이 프로그램은 M2에 있는 프로그램으로 메시지를 보낸다. 컴퓨터는 사람보다 빠르기 때문에 M1의 프로그램은 M2로 부터 응답을 받는데 몇 ms 밖에 걸리지 않는다. 두번째 프로그램은 M1으로부터 메시지를 받는데 몇 ms가 걸리고, 첫번째 프로그램이 아직 활성화가 되지 않았다고 결론을 내고 에러 메시지를 보여주고 나간다. 그럼 한쪽은 계속 프로그램을 실행시키더라도 상호소통할 수 없다. Socket 소캣의 개념 호스트의 네트워크 스택에 연결된 어플리케이션을 위한 인터페이스 소켓 API 32-bit 노드 주소 IP address 16-b.. C/C++ programming tutorial C/C++ programming tutorial 1. C Basics 1.1 source code #include int main() { printf("Hello world\n"); return 0; } 1.2 How to compile $ gcc hello.c -o hello gcc : 컴파일링 명령 hello.c : 소스 파일 이름 hello : 컴파일러로 만들어낸, 실행 가능한 파일 executable file 설정하지 않으면 a.out이 디폴트 1.3 How to execute ./hello 1.4 Data types 1.5 Variable Declaration example int length = 100; char num = '9' // The actual value is 57 (based on.. 분할 정복 Divide and Conquer 알고리즘으로 행렬 곱셈 matrix multiplication 풀기 분할 정복 Divide and Conquer : 행렬 곱셈 matrix multiplication problem Program the divide and conquer matrix multiplication using 1) standard algorithm 2) recursion For the two cases 1) and 2), Compare the number of computations (multiplication, addition, and subtraction) between 1), 2) cases. In the matrix computation of C = A×B, matrices A and B are filled with rand()%1000, execute srand(time(NULL)) f.. 합병 정렬 : Merge Sort 내림차순으로 구현하기 합병 정렬 Merge Sort 성균관대학교 소프트웨어학과 조대호 교수님의 2020년도 2학기 알고리즘 수업을 듣고 수행한 과제입니다. 배열을 내림차순으로 정렬하는 합병 정렬을 C로 구현하였습니다. input and output conditions Test the function with the following three types of integer inputs. int A[100] : filled with rand()%1000, execute srand(time(NULL)) first, (stdlib.h, time.h should be included) (Duplicate keys are ignored.) int A[100] : already sorted (Write a function for fil.. 이전 1 2 다음