C++

📝 개요 (1) 자식 노드 갯수가 2개 이하로 (2) 왼쪽 자식은 모두 나보다 값이 작고 (3) 오른쪽 자식은 모두 나보다 값이 큰 그리고 모든 자식 노드 또한 위 3가지 성질을 갖는 자료구조. When to use? (1) Local Search getNextNode (next Largest key except myself) Range Search ex) 1~100 中 5~15 (2) Implements Data structure Set, Binary Heap, Priority Queue 👨‍💻 Impelment (C++) 왼쪽, 오른쪽 자식뿐만 아니라 부모노드와 연결도 킵 BST.h BST.cpp main.cpp Key Point (Delete Node) 가장 까다로운 부분이기 때문에 그림과 함께 정..
🔒 문제 🔑 풀이 (C++) #include #include #include #define MIN_VALUE 0 #define MAX_VALUE 255 using namespace std; bool has_only_digits(const string s){ // dot(.) == "\000" return s.find_first_not_of( "0123456789" ) == string::npos && (s != "\000"); } /* The function returns 1 if IP string is valid else return 0 You are required to complete this method */ int isValid(string s) { if (count(s.begin(), s.en..
What's Iterator? Container를 순회하는 포인터. When To Use? Convenient Programming loop without [] operator or minding 'range' Reusabililty we can reuse iterator when to change data container Dynamic add & remove (1) ⭐ 범위 신경쓰기 싫다. index 극혐이다. #include #include using namespace std; int main() { // Declaring a vector vector v = { 1, 2, 3 }; // Declaring an iterator vector::iterator i; int j; cout
🔒 문제 구분자가 .이 아니라 ' ' 공백이 여러개 들어왔을 경우에 뒤집는 풀이 🔑 풀이 (C++) #include #include using namespace std; string reverseWords(string S) { int endIndex = S.length(); string result = ""; while (endIndex > 0) { while (endIndex > 0 && S[endIndex--] == ' '); int startIndex = endIndex; while (startIndex > 0 && S[--startIndex] != ' '); if (startIndex != 0) { string word = S.substr(startIndex + 1, endIndex - start..
🔒 문제 💭 생각의 흐름 배열은 선형 자료구조로 전체 길이 / 2를 기준으로 좌우 대칭을 이루고있다. 맨 첫자리 끝자리 첫자리 + 1 끝자리 - 1 index를 사용하여 대칭을 이루는 문자열을 Swapping 해주기만 하면 된다. 🔑 풀이 (C++) string reverseWord(string str){ char characterArray[str.length() + 1]; const int length = sizeof(characterArray); strncpy(characterArray, str.c_str(), length); // after strncpy null-terminate character should not be created characterArray[length] = '\0'; for..
Complete Binaray Tree every level, all nodes are filled ordering left to right except possibly last node When to use? -> Implements Prirority Queue! * Full Binrary Tree : every node has two children ADT of Prirority Queue implements using MAX Heap array -> parent index : i / 2 left child index : i * 2 right child index : i * 2 + 1 maxSize: Capacity size: The number of current elements which heap..
M_Falcon
'C++' 태그의 글 목록