'C++'에 해당되는 글 2건

  1. 2023.06.09 [CPP] 펜윅 트리 (Fenwick Tree)
  2. 2016.03.17 Lambda function 1
Coding/CPP 삽질기2023. 6. 9. 23:14
#include <iostream>

const int MAX_SIZE = 10;

void update(int* TREE, int idx, int value) {
    for (++idx; idx <= MAX_SIZE+1; idx += (idx & -idx))
        TREE[idx] += value;
}

int sum(int *TREE, int s) {
    int r = 0;
    for (++s; s > 0; s &= (s-1))
        r += TREE[s];
    return r;
}

int main(int argc, char **argv) {
    int TBL[MAX_SIZE] = {0};
    int TREE[MAX_SIZE+1] = {0, };

    for (auto i = 0; i < MAX_SIZE; i++) {
        TBL[i] = i+1;
        update(TREE, i, TBL[i]);
    }

    // GET SUM from 1 ~ N
    for (auto i = 0; i < MAX_SIZE; i++)
        std::cout << sum(TREE, i) << ", ";
    std::cout << std::endl;
    
    return 0;
}
Posted by chobocho
Coding/CPP 삽질기2016. 3. 17. 00:56

[ C++ Lambda 함수 설명 ]

https://msdn.microsoft.com/ko-kr/library/dd293608.aspx

https://msdn.microsoft.com/ko-kr/library/dd293599.aspx

http://en.cppreference.com/w/cpp/language/lambda


'Coding > CPP 삽질기' 카테고리의 다른 글

C++ 컴파일러  (0) 2016.03.30
Lambda function  (0) 2016.03.16
짝수만 출력하기  (0) 2016.03.03
Posted by chobocho