anonymous
  • anonymous
what is the difference between ++top and top++in data structures and algorithms in java?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
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.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
ajprincess
  • ajprincess
Guess u r referring the one that comes in stack @Zaara. Right?
anonymous
  • anonymous
yes u r ryt.... im littl confused with dat.....
ajprincess
  • ajprincess
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?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
just compare ++top and top++... i like to knw the difference...
asnaseer
  • asnaseer
++top means "first increment top, then read its new value" top++ means "read the current value of top, then increment it" e.g. top = -1; x = ++top; will result in x=0, top=0 whereas: top = -1; x = top++; will result in x=-1, top=0
anonymous
  • anonymous
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. For example top= 10; newTop = ++top; System.out.println(newTop); prints 11, but top = 10; newTop = top++; System.out.println(newTop); prints 10 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...

Looking for something else?

Not the answer you are looking for? Search for more explanations.