java 6

[C++ Fundamentals of Data Structures/C++ 자료구조론(이석호)] 5.6 히프 연습문제

2. void MinHeap ::: Push(const T& e) { if(heapSize == capacity) { Change1D(heap, capacity, 2*capacity); capacity *= 2; } int currentNode = ++heapSize; //데이터가 들어갈 위치 : heapSize + 1 while (currentNode !=1 && heap[currentNode/2] > e) { heap[currentNode] = heap[currentNode/2]; currentNode /= 2; } heap[currentNode] = e; } void MinHeap :: Pop() { if(IsEmpty()) throw "Heap is empty."; heap[1]. ~T(); //..

[C++ Fundamentals of Data Structures/C++ 자료구조론(이석호)] 5.4 이진 트리의 추가 연산 연습문제

1. 이진 트리에서 리프 노드의 수를 계산하는 C++ 함수를 작성하라. 이 함수의 계산 시간은 얼마인가? int get_leaf_count(TreeNode *ptr) { int count = 0; if(ptr != NULL) { if(ptr->leftChild == NULL && ptr->rightChild == NULL) return 1; else count = get_leaf_count(ptr->leftChild) + get_leaf_count(ptr->rightChild); } return count; } 2. 이진 트리에 있는 모든 노드의 왼쪽 자식과 오른쪽 자식을 교환하는 C++ 함수 SwapTree()를 작성하라. TreeNode* Tree :: SwapTree(TreeNode *origNod..

[C++ Fundamentals of Data Structures/C++ 자료구조론(이석호)] 4.10 이중 연결 리스트

- 이중 연결 리스트 #include using namespace std; class DblList; class DblListNode { friend class DblList; private: int data; DblListNode* left, * right; public: DblListNode(int element, DblListNode* lNode = NULL, DblListNode* rNode = NULL) { data = element; left = lNode; right = rNode; } }; class DblList { private: DblListNode* head; DblListNode* tail; int size; public: explicit DblList(int element) { ..

[C++ Fundamentals of Data Structures/C++ 자료구조론(이석호)] 4.2 C++에서의 체인 표현 연습 문제

다음 연습문제들은 모두 4.2.4.절의 정의들을 기반으로 하고 있다. 모든 함수들은 클래스 Chain의 멤버 함수로 구현되는데, 그래서 이들은 ChainNode의 데이타 멤버들에 접근할 수 있다고 가정한다. 1. 체인에 있는 노드의 수를 계산하는 C++ 함수 length를 작성하라. 이 함수의 시간 복잡도는 얼마인가? * 시간 복잡도 : O(n) * 참고 : https://jaimemin.tistory.com/159 2. x를 체인에 있는 임의의 노드를 지시하는 포인터라고 하자. 체인으로부터 이것을 삭제하는 C++ 함수를 작성하라. 만일 x == first라고 하면, first는 체인에서 새로 첫 번째가 된 노드를 가리키도록 반드시 재설정 되어야 한다. 이 함수의 시간 복잡도는 얼마인가? * 시간 복잡도..

[C++ Fundamentals of Data Structures/C++ 자료구조론(이석호)] 2.6 스트링 추상 데이타 타입 연습문제

1,2,3,4,5번 문제 전체 코드 //String.h의 헤더파일 #ifndef String #include using namespace std; class String { private: char* str; int len; int* f; public: String(char* init, int m) :len(m) { str = new char[m + 1]; f = new int[m]; for (int i = 0; i < m; i++) str[i] = init[i]; str[m] = '\0'; //문자열의 끝은 항상 널이다 FailureFunction(); } ~String() { if (str != NULL) { delete[]str; str = NULL; } if (f != NULL) { delete[..

[C++ Fundamentals of Data Structures/C++ 자료구조론(이석호)] 2.3 다항식 추상 데이타 타입 연습문제

2. //출력 결과 * a,b배열을 랜덤으로 생성한 뒤, 오름차순 정렬하고 두 배열에 같은 값이 있는지 확인 후 길이 비교하여 -1, 0, 1 출력 되도록 클래스 생성 *참고 : https://jaimemin.tistory.com/138 3. 함수 Add를 수정해서 실행을 끝내기 전에 c.termArray의 크기를 c.terms로 줄일 수 있도록 하라. 이 수정으로 데이타 멤버 capactiy를 사용하지 않아도 되는가? * 추가된 부분이 c.termArray의 크기를 c.terms로 줄이는 부분. * 참고 : https://jaimemin.tistory.com/138 * 사실 이해 안 됏음 ㅜ.. 4. 이 절에서 표현한 방식의 다항식을 입력하고 출력하는 C++ 함수를 작성하라. 이 함수는 >> 연산자를 ..