728x90

CS/자료구조 20

[ 자료구조 ] level order iterative inorder tree traversal

[ 자료구조 ] level order iterative inorder tree traversal 1. 반복적 중위 탐색(inorder traversal) 알고리즘 트리 탐색을 꼭 순환 알고리즘으로 작성해야 하는 것은 아니다. 아래 예는 중위 탐색 알고리즘을 반복적인 알고리즘으로 작성한 것이다. 각 노드를 방문하면서 과거 노드를 LIFO 순으로 기억해야 하기 때문에 스택을 사용하였다. void iter_inorder(tree_ptr node){ int top = -1; tree_ptr stack[MAX_STACK_SIZE]; while(1){ while(node){ push(&top, node); node = node->left_child; } node = pop(&top); if(!node) break;..

CS/자료구조 2021.11.29

[ 자료구조 ] inorder preorder postorder traversal 탐색 알고리즘

[ 자료구조 ] inorder preorder postorder traversal 탐색 알고리즘 1. 중위 탐색 (inorder traversal) 알고리즘 , 왼나오 중위 탐색 트리 알고리즘은 순환 알고리즘이 간단하다. void inorder(tree_ptr ptr) { if(ptr) { inorder(ptr->left_child); printf(“%d”,ptr->data); inorder(ptr->right_child); } } 2. 전위 탐색 (preorder traversal) , 나왼오 순환 알고리즘이다, 전위 탐색으로 모든 트리를 탐색한다. void inorder(tree_ptr ptr) { if(ptr) { printf(“%d”,ptr->data); inorder(ptr->left_child..

CS/자료구조 2021.11.28

[ 자료구조 ] Tree Linked List로 구현하기 (2)

[ 자료구조 ] Tree Linked List로 구현하기 (2) #include #include struct tnode { int data; struct tnode* left_child; struct tnode* right_child; }; typedef struct tnode node; typedef node* tree_ptr; int main(){ int i; tree_ptr head = NULL, temp = NULL; temp = (tree_ptr)malloc(sizeof(node)); temp->data = 0; temp->left_child = NULL; temp->right_child = NULL; head = temp; tree_ptr head = NULL, temp = NULL; temp..

CS/자료구조 2021.11.27

[ 자료구조 ] Tree Linked List로 구현하기 (1)

[ 자료구조 ] Tree Linked List로 구현하기 (1) #include #include struct tnode{ int data; struct tnode * left_child; struct tnode * right_child; }; typedef struct tnode node; typedef node * tree_ptr; tree_ptr insert(tree_ptr head, int * number){ tree_ptr tnodes[5]; tree_ptr temp = NULL; for(int i = 0; idata = number[i]; tnodes[i]->left_child = tnodes[i]->right_child = NULL; } head = tnodes[0]; tnodes[0]->le..

CS/자료구조 2021.11.26

[ 자료구조 ] linked list 원형 연결 리스트 이중 연결 리스트

[ 자료구조 ] linked list 원형 연결 리스트 이중 연결 리스트 linkedlist에서 뒤의 노드를 읽는 것은 링크로 연결해줘야 하기 때문에 읽기, 삭제하기, 삽입하기가 어렵다. 이를 개선하기 위해 원형 연결 리스트와 이중 연결 리스트가 등장했다. 연결 리스트의 데이터 개수가 n개 일 때 n번의 링크를 따라가야 한다 => O(n) 원형 연결 리스트 원형 연결 리스트 : 연결 리스트의 맨 끝 노드를 첫 번째 노드와 연결시켜 원형으로 만든 리스트이다. 맨 끝 링크는 맨 앞 노드를 가리킨다. 포인터는 맨 끝 노드를 가리킨다. => 맨 끝과 맨 앞을 바로 찾을 수 있다. 단순 원형 리스트 삽입 삭제 맨 처음 O(1) O(1) 맨 마지막 O(1) O(n) 원형 연결 리스트의 맨 뒤에 노드를 삽입하는 알고..

CS/자료구조 2021.11.03

[ 자료구조 ] O 표기법, 큐, 스택

[ 자료구조 ] O 표기법, 큐, 스택 1. 요구사항 분석(Requirement Analysis) 프로그램 개발 사용자, 기능, 성능, 기능, 요구사항 2. 설계 (Design) 플로우 차트 등 설계 도구 사용 3. 프로그래밍 (Programming) 플로우 차트를 프로그램 언어로 바꾼다. 4. 테스트 (Testing) 사용자에 세 샘플 데이터를 받아 실험한다. 5. 사용 (Use) 전달받아 사용, 설치, 수행, 해결방법 전달 6. 사용 및 보수 단계 (Maintenance) 프로그램 기능 수행이 정확해야 한다. MAX , MIN, MID 선언하고 두 개씩 비교 left middle right 0 5 10 6 8 10 6 6 (6.5) 실수 버림 7 7 7 7 알고리즘 : 어떤 일을 하는 절차 정의 : ..

CS/자료구조 2021.11.02
728x90