Iterate from the middle

From Yefu's notes
Jump to: navigation, search
#include <iostream>
#include <string>
#include <vector>


int main()
{
    int N=3;
    for(int i=0; i<N; i++)
    {
        int sign = ( (i%2)*2-1  );
        int signN  = ( (N%2)*2-1  );
        int index =  ( N +signN* i*sign)/2;

        std::cout<<index<<std::endl; 
    }
    
    return 0;
}