본문 바로가기

알고리즘7

[C++] vector<object>일 때 object의 Value 값으로 sort하기 (struct, std::sort이용) 알고리즘 문제 풀다가 int key, int value 로 저장하고 이를 value 값을 기준으로 정렬할 일이 생겼다. 이를 해결한 내용을 기록으로 남기고 공유하고자 글을 쓴다. 풀던 문제 링크 www.hackerrank.com/challenges/jim-and-the-orders/problem?h_r=profile key, value로 이루어진 객체를 value 값을 기준으로 sorting한다고 생각해보자, map을 이용하여 해쉬값을 저장하고 value값으로 이루어진 vector를 추가적으로 생성하는 방법이 있는데 이는 비교적 low레벨인 C++ 언어를 사용하는데 불필요한 일을 너무 많이 하는 것 같다고 느껴졌다. 찾아낸 방법이 비교 struct를 생성하고 이를 std::sort함수의 비교 함수 객체로.. 2020. 5. 23.
[자료구조] Program to find maximum width of a binary tree 원문 링크 : https://www.javatpoint.com/program-to-find-maximum-width-of-a-binary-tree Program to Find Maximum Width of a Binary Tree - javatpoint Program to Find Maximum Width of a Binary Tree on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph etc. www.javatpoint.com 여기서 width란 한 level의 node의 수를 의미한다. 따라서 maximum width라 함은, 한 level에 있.. 2020. 3. 19.
[자료구조] Program to determine whether two trees are identical 원문링크 : https://www.javatpoint.com/program-to-determine-whether-two-trees-are-identical Program to Determine Whether two Trees are Identical - javatpoint Program to Determine Whether two Trees are Identical on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph etc. www.javatpoint.com 초기 알고리즘 구상 exception if root is null compare group .. 2020. 3. 10.
[자료구조] Binary Search Tree, construction, deletion, In-order traversal 원문링크 : https://www.javatpoint.com/program-to-construct-a-binary-search-tree-and-perform-deletion-and-inorder-traversal Program to Construct a Binary Search Tree and Perform Deletion and Inorder Traversal - javatpoint Program to Construct a Binary Search Tree and Perform Deletion and Inorder Traversal on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, lin.. 2020. 3. 3.