You are viewing a single comment's thread. Return to all comments →
My logical brain took over and I didn't even second thought that it can be easily done with std::min(p / 2, n / 2 - p / 2);
int pageCount(int numOfPages, int pageNum) { int count1 = 0; int count2 = 0; if (numOfPages == pageNum || pageNum == 1){ return 0; } for (int i = 2; i <= numOfPages; i+=2){ count1++; if (i == pageNum || i+1 == pageNum){ break; } } if (numOfPages%2 != 0){ count2--; for (int i = numOfPages; i >= 2; i-=2){ count2++; if (i == pageNum || i-1 == pageNum){ break; } } } else { for (int i = numOfPages-1; i >= 2; i-=2){ count2++; if (i == pageNum || i-1 == pageNum){ break; } } } return (count1 > count2) ? count2 : count1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Drawing Book
You are viewing a single comment's thread. Return to all comments →
My logical brain took over and I didn't even second thought that it can be easily done with std::min(p / 2, n / 2 - p / 2);