함수 포인터 (typedef, using, std::function)
·
C++
#include #include #include using namespace std;//C++ 11에서 지원하는 using을 이용하여 별칭 만들기using customInt = int; /*; /* vi1;//Test Printvoid print(int index){ cout (typedef 반환형(*변수이름)(매개변수);) typedef void(*fp1)(int); fp1 func1 = print; func1(1); //C++ 11에서 지원하는 using을 이용한 함수 포인터 -> (using 변수이름 = 반환형(*)(매개변수);) using fp2 = void(*)(int); fp2 func2 = print; func2(2); //C++ 11에서의 std::function //#include..
C++ Linked List
·
C++
Template과 Node를 이용하여 간단하게 linked list 구현을 시도해보았다. Template을 통한 다양한 자료형을 이용할 수 있도록 하며, 뒤쪽부터 삽입하는 Push와 뒤쪽부터 데이터를 제거하는 Pop 전체 데이터를 정리하는 Clear, 데이터의 개수를 반환하는 size함수까지 구현해보았다. #include using namespace std;template class Node{public: Node() : Value(0), Next(nullptr) {} T Value; Node* Next;};template class linklist{public: linklist() : NodeCount(0), Head(nullptr) {}; ~linklist();public: void Prin..
OpenGL : Laplacian Smoothing & Taubin Smoothing
·
C++
Laplacian Smoothingvoid Mesh::Laplacian(int iter){ vector> newPos; for (int it = 0; it _pos; Vec3 p; for (auto nv : v->_nbVertices) { p += (nv->_pos - pos) / 2.0f; } p /= v->_nbVertices.size(); pos += p; newPos.push_back(pos); } for (int i = 0; i _pos = newPos[i]; } newPos.clear(); } computeNormal();}Taubin Smoothingvoid Mesh::Taubin(int iter){ vector> newPos; for (int it = ..
cout 소수점 고정
·
C++
coutcout.precision(6) = 6자리까지 표현하겠다는 뜻.-> 버리는 자리 수는 반올림! cout해제 : cout.unsetf(ios::fixed)설정 : cout.setf(ios::fixed)로 표현 이 가능하다.
string::find
·
C++
string 클래스의 멤버함수 헤더 : #include 반환값 :1. 찾는 문자의 첫번째 인덱스 값2. 찾는 문자가 없는경우 string::npos를 리턴 (no position이라는 뜻으로 쓰레기 값) #include #include using namespace std;int solution(string str1, string str2) { int answer = 0; if(str1.find(str2)!=string::npos) { return 1; } else { return 2; } return answer;}
STL : sort algorithm
·
C++
헤더 : #include  sort(start,end) -> [start,end) 범위 인자 오름차순(default)정렬quick sort 기반으로 구현되어 있어 시간 복잡도는 n log n 사용법1. sort(arr,arr+n);2. sort(v.begin(),v.end());3. sort(v.begin(),v.end(), compare); //사용자 정의 함수4. sort(v.begin(),v.end(), greater()); //내림차순5. sort(v.begin(),v.end(), less()); //오름차순