Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Zaara Group Title

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
  1. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Guess u r referring the one that comes in stack @Zaara. Right?

    • one year ago
  2. Zaara Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yes u r ryt.... im littl confused with dat.....

    • one year ago
  3. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 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
  4. Zaara Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    just compare ++top and top++... i like to knw the difference...

    • one year ago
  5. asnaseer Group Title
    Best Response
    You've already chosen the best response.
    Medals 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
  6. hduff Group Title
    Best Response
    You've already chosen the best response.
    Medals 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
    • Attachments:

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.