0

なぜこれが理にかなっているのか誰かが私に説明できますか(それheapはaであることに注意してくださいvector<int>):

// Heap Sort
int parent = 0;
int leftChild = (parent * 2) + 1;
int rightChild = (parent * 2) + 2;

// This conditional works fine. Code doesn't enter block when heap.size() is zero.
while (leftChild < heap.size()) {} 

でも:

// Code does enter this block when heap.size() is 0? Why?
while (leftChild < (heap.size() - 1) {}

がどういうわけか「真実」と解釈されているため、これが発生していると感じますが、その-1方法がわかりませんleftChild(デフォルトでは10または-1.

4

1 に答える 1