Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
what is the difference between ++top and top++in data structures and algorithms in java?
 one year ago
 one year ago
what is the difference between ++top and top++in data structures and algorithms in java?
 one year ago
 one year ago

This Question is Closed

ajprincessBest ResponseYou've already chosen the best response.0
Guess u r referring the one that comes in stack @Zaara. Right?
 one year ago

ZaaraBest ResponseYou've already chosen the best response.0
yes u r ryt.... im littl confused with dat.....
 one year ago

ajprincessBest ResponseYou've already chosen the best response.0
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?
 one year ago

ZaaraBest ResponseYou've already chosen the best response.0
just compare ++top and top++... i like to knw the difference...
 one year ago

asnaseerBest ResponseYou've already chosen the best response.1
++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
 one year ago

hduffBest ResponseYou've already chosen the best response.1
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...
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.