본문 바로가기

전체 글

(55)
6. 트리 (Tree) 링크 표현의 class 선언 class Tree;// 전방 선언 class TreeNode{ friend class Tree; private: TreeNode *LeftChild; char data; TreeNode *RightChild; }; class Tree { public: // tree 연산 private: TreeNode *root; }; 중위순회 void Tree::inorder(){ // Driver // tree class의 공용 멤버 함수 inorder(root); } void Tree::inorder(TreeNode *CurrentNode){ // Workhorse // tree class의 전용 멤버 함수 if (CurrentNode) { inorder(CurrentNode->Lef..
트리 (Tree) 기본 용어 Tree 정의 : node로 이루어진 유한집합으로 root node와 나머지 노드 (T_1, T_2, ..., T_n)으로 분리. 이때 T_i는 각각 하나의 tree (sub tree 혹은 부분 tree)라 함 node의 차수(degree) 해당 node의 sub tree 수 tree의 차수 tree에 포함된 node들 중 최대 차수 리프(leaf) 또는 단말노드(terminal) 차수가 0인 node ex) K, L, F, G, M, I, J 비단말노드(non-terminal) 차수가 0이 아닌 node ex) A, B, C, D, E, H 레벨(level) root level이 1일 때 부모-자식은 1 level씩 증가 tree 깊이(depth) 또는 높이(height) tree에 속한 n..
5-1. 이중 연결 리스트 (Doubly Linked List) 단순 연결 리스트 단점 보완 - 전위 node 접근을 용이하게 하기 위해 양방향 연결 field 가짐 이중 연결 리스트 class 정의 class DblList;// 전방 선언 class DblListNode { friend class DblList; private: int data; DblListNode *left, *right; }; class DblList { public: // 연산 함수 private: DblListNode *first;// head node }; 이중 연결 원형 리스트 삽입 void DblList::Insert (DblListNode *p, DblListNode *x){ // node x 오른쪽에 node p 삽입 p->left = x; p->right=x->right; x->..
4-1. 연결 큐 (Linked Queue) 연결 리스트로 Queue 구현 Queue Class 정의 class LinkedQueue;// 전방 선언 class ChainNode { friend class LinkedQueue; private: int data; ChainNode *link; public: ChainNode (int element=0, ChainNode* next=0) // 생성자 { data=element; link=next; } }; class LinkedQueue{ private: ChainNode *top; public: LinkedQueue() { top=0; };// 생성자 void Push(const int&);// 삽입 함수 int* Pop(int&)// 삭제 함수 }; Linked Queue 삽입 void Linke..
3-1. 연결 스택 (Linked Stack) 연결 리스트로 Stack 구현 Stack Class 정의 class LinkedStack;// 전방 선언 class ChainNode { friend class LinkedStack; private: int data; ChainNode *link; public: ChainNode (int element=0, ChainNode* next=0) // 생성자 { data=element; link=next; } }; class LinkedStack{ private: ChainNode *top; public: LinkedStack() { top=0; };// 생성자 void Push(const int&);// 삽입 함수 int* Pop(int&)// 삭제 함수 }; 연결 Stack 삽입 함수 void Linked..
5. 연결 리스트 (Linked List) 노드 삽입 노드 삭제 복합 class 사용한 정의 class ThreeLetterChain;// 전방 선언 class ThreeLetterNode{ friend class ThreeLetterChain; // ThreeLetterChain 멤버함수가 ThreeLetterNode 데이터 멤버 접근 가능 private: char data[3]; ThreeLetterNode *link; }; class ThreeLetterChain { public: // list 연산 private: ThreeLetterNode *first; }; 중첩 class 사용한 정의 class ThreeLetterChain { public: // list 연산 private: class ThreeLetterNode {// 중첩 cl..
4. 큐 (Queue) dyeoma.tistory.com/4 자료구조 개념, 종류 자료구조란? 일련의 자료들을 조직하고 구조화 하는 것 ex) 배열, 연결리스트, 트리, ... 성능 분석 공간 복잡도 - 필요한 공간의 크기 시간 복잡도 - 필요한 실행문의 실행 횟수 1. 배열 (Array) 인�� dyeoma.tistory.com Queue 선언 Private: T *queue; int front, rear; int capacity; template Queue::Queue (int queueCapacity): capacity (queueCapacity){ if(capacity 0"; queue = new T[capacity]; front =rear-1; } 초기..
3. 스택 (Stack) dyeoma.tistory.com/4 자료구조 개념, 종류 자료구조란? 일련의 자료들을 조직하고 구조화 하는 것 ex) 배열, 연결리스트, 트리, ... 성능 분석 공간 복잡도 - 필요한 공간의 크기 시간 복잡도 - 필요한 실행문의 실행 횟수 1. 배열 (Array) 인�� dyeoma.tistory.com Stack class 선언 Private: T *stack;// stack 원소 저장 배열 int top;// top 원소 위치 int capacity;// stack 배열 크기 Template Stack::Stack (int stackCapacity): capacity(stackCapacity){// 생성자 if(capacity 0"..