Algorithm/알고리즘 예제코드

    GCD와 LCM

    function greatestCommonDivisor(a, b) {return b ? greatestCommonDivisor(b, a % b) : Math.abs(a);} function leastCommonMultipleOfTwo(a, b) {return (a * b) / greatestCommonDivisor(a, b);} function gcdlcm(a, b) { return [greatestCommonDivisor(a, b),leastCommonMultipleOfTwo(a, b)]; } function gcd(a, b) { if (a < b) { let temp = a; a = b; b = a; } while (b !== 0) { let n = a % b; a = b; b = n; } retur..

    [알고리즘 예제][그래프탐색]BFS

    void BFS(int node){ bool visited[MAX] = {false}; queue q; q.push(node); visited[node] = true; while(!q.empty()){ int cur = q.front(); for(int next=0; next

    [알고리즘 예제][정렬]Q_sort.

    #include #include using namespace std; void quickSort(vector &v, int i, int j) { // 벡터의 크기가 0이나 1. if(i>=j) return; int pivot = v[(i+j)/2]; int left = i; int right = j; while(left