본문 바로가기

전체 글547

Binary Search / Breadth First Search / Depth First Search Binary Search #include using namespace std; int BinarySearch(int dataArr[], int size, int findData) {int low = 0, high = size - 1, mid;while (low findData) high = mid - 1;else if (dataArr[mid] < findData) low = mid + 1;else return mid;}return -1;} int main(){int dataArr[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,24 };int length = sizeof(dataArr) / sizeof(dataArr[0]);int input, r.. 2017. 10. 18.
Function Template / Function template #include using namespace std; templatevoid Swap(T& num1, T& num2){T temp = num1;num1 = num2;num2 = temp;} int main(){int num1 = 10, num2 = 40;cout 2017. 10. 18.
Inheritance Overriding / Virtual Function #include using namespace std; class A {public:void over() { cout 2017. 10. 18.
Struct #pragma warning(disable:4996) #include #include char copy_str(char *dest, char *src); struct Books {char name[30];char auth[30];char publ[30];int isborrowed;}; int main() {struct Books Harry_Potter; copy_str(Harry_Potter.name, "Harry Potter");copy_str(Harry_Potter.auth, "J.K Rolling");copy_str(Harry_Potter.publ, "Scholastic");Harry_Potter.isborrowed = 0; printf("Book name: %s\n", Harry_Potter.na.. 2017. 10. 18.
Function pointer 특정 변수에 대한 메모리 주소를 담을 수 있는 변수를 포인터 변수,특정 함수에 대한 메모리 주소를 담을 수 있는 변수를 함수 포인터. 프로그램 코드가 간결해집니다.중복되는 코드를 줄일 수 있습니다.상황에 따른 함수를 호출할 수 있습니다. int (*FuncPtr)(int, int) int add(int first, int second)1. FuncPtr = add2. FuncPtr = &add #include #include typedef int(*calcFuncPtr)(int, int); int plus(int first, int second){return first + second;} int minus(int first, int second){return first - second;} int calc.. 2017. 10. 18.
.so Library // mymath.h #include extern int sum(int n1, int n2); // mymath.c #include "mymath.h" int sum(int n1, int n2) { return n1 + n2; } //main.c #include "mymath.h"#include #include #include #include int main(int argc, char **argv){void *handle = NULL;int(*result)(int, int); handle = dlopen("./libmymath.so", RTLD_NOW); if(!handle){printf("fail to dlopen, %s\\n", dlerror());return 0;} result = dlsym(han.. 2017. 10. 17.
opencv mouseevent #include "opencv.hpp"using namespace cv;using namespace std;void onMouse(int event, int x, int y, int flags, void* param);int main(){Mat dstImage(512, 512, CV_8UC3, Scalar(255, 255, 255)); imshow("dstImage", dstImage);setMouseCallback("dstImage", onMouse, (void *)&dstImage); waitKey(); return 0;}void onMouse(int event, int x, int y, int flags, void* param){Mat *pMat = (Mat *)param;Mat image = Ma.. 2017. 9. 5.
harris corner detection #include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include #include #include using namespace cv;using namespace std; /// Global variablesMat src, src_gray;int thresh = 200;int max_thresh = 255; char* source_window = "Source image";char* corners_window = "Corners detected"; /// Function headervoid cornerHarris_demo(int, void*); /** @function main */int main(int argc, cha.. 2017. 9. 3.
병합 정렬 분할 정복이라는 알고리즘 디자인 기법에 근거하여 만들어진 정렬 방법입니다. 분할 정복이란, 말 그대로 복잡한 문제를 복잡하지 않은 문제로 분할하여 정복하는 방법입니다. 단 분할해서 정복했으니 정복한 후에는 결합의 과정을 거쳐야 합니다. 해결이 용이한 단계까지 문제를 분할해 나갑니다. 해결이 용이한 수준까지 분할된 문제를 해결합니다. 분할해서 해결한 결과를 결합하여 마무리 합니다. 8개의 데이터를 동시에 정렬하는 것보다, 이를 둘로 나눠서 4개의 데이터를 정렬하는 것이 쉽고, 또 이들 각각을 다시 한번 둘로 나눠서 2개의 데이터를 정렬하는 것이 더 쉽다. 오름차순 정렬을 기준으로 병합 정렬으 기본 원리를 설명하고 있습니다. 8개의 데이터를 둘로 나눈 것이 전부이지만, 실제로는 훨씬 더 작게 분할을 해야 합.. 2017. 8. 12.
정렬 각종 정렬 알고리즘을 소개하고자 합니다. 알고르짐을 코드 레벨에서 분석만 한다면 지루할 수 있습니다. 이보다는 각각의 알고리즘이 갖는 특징에 관심을 두고 공부하는 것이 오래 남고 더 의미가 있을 것입니다. 버블 정렬 이해와 구현버블 정렬은 정렬의 대명사로 알려져 있는, 여러분이 알고 있을만한 정렬방법입니다. 이해하기도 구현하기도 쉽습니다. 물론 이해와 구현이 쉬운 만큼 성능에는 아쉬움이 있습니다. 그럼 3, 2, 4, 1이 순서대로 저장된 다음 그림의 배열을 오름차순(값이 클수록 뒤에 위치시키는 방법)으로 정렬하는 과정을 보이면서 버블 정렬의 과정을 소개하겠습니다. 버블 정렬은 인접한 두 개의 데이터를 비교해가면서 정렬을 진행하는 방식입니다. 두 데이터를 비교하여, 정렬순서상 위치가 바뀌어야 하는 경우에.. 2017. 8. 10.