what is the difference between ++top and top++in data structures and algorithms in java?
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Guess u r referring the one that comes in stack @Zaara. Right?
yes u r ryt.... im littl confused with dat.....
when u initialize the top u give the value -1 which means that there is no element in the stack.If there is one element the index of top will be 0. when u insert the first element the index shoud be iterated from -1 to 0. In this case u use ++top. The iteration has to be done before the insertion. Am I clear?
Not the answer you are looking for? Search for more explanations.
just compare ++top and top++... i like to knw the difference...
++top means "first increment top, then read its new value"
top++ means "read the current value of top, then increment it"
top = -1;
x = ++top;
will result in x=0, top=0
top = -1;
x = top++;
will result in x=-1, top=0
asnaseer has nailed it...
Java has two increment/decrement operators: ++ and --. These operators can be used both before and after the operand they are applied to. When used before they carry out prefix incrementing or decrementing. When used after the operand they carry out postfix incrementing or decrementing. The results are different in each case.
newTop = ++top;
prints 11, but
top = 10;
newTop = top++;
In the second line of the first case top is incremented by 1 and then newTop is initialized with top.
In the second line of the second case newTop is incremented to the value of Top and then Top is incremented.
Hope this helps...