java - Why use "s = --size" instead of "s = size"? -


code priorityqueue:

private e removeat(int i) {     assert >= 0 && < size;     modcount++;     int s = --size;        //    <- why???     if (s == i) // removed last element         queue[i] = null;     else {         e moved = (e) queue[s];         queue[s] = null;         siftdown(i, moved);         if (queue[i] == moved) {             siftup(i, moved);             if (queue[i] != moved)                 return moved;         }     }     return null; } 

what's differences between s = --size , s = size? help? in advance.

int s = --size; pre-decrement operator, , not equivalent int s = size;. equivalent to

int s = (size = (size - 1)); 

or

size = size - 1; int s = size; 

but shorter both of those.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -