3 Replies - 468 Views - Last Post: 07 October 2012 - 10:25 AM Rate Topic: -----

#1 berserker7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-October 12

Set elements of stack java

Posted 05 October 2012 - 07:45 AM

Hi. I have to resolve some homework question. By using a series of instruction pop(), push(), peek() and empty(, i need to carry out some instruction.
- For example, set x to the 2nd element of stack, leaving stack without top element so it will be pop(s) and x=peek(s).

- Then I have example 2: instruction - set x to third element of stack, leaving stackk unchanged.

What you think about this sequence: pop(s),pop(s), x=peek(s), push(s), push(s), pop(s), pop(s), push(s),push(s)?

Is This A Good Question/Topic? 0
  • +

Replies To: Set elements of stack java

#2 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Set elements of stack java

Posted 05 October 2012 - 09:47 AM

Wait. How are we suppose to know what element we are on? We don't know the size of the stack.
Also. The peek and pop methods have no arguments so is S suppose to be the stack?
Was This Post Helpful? 0
  • +
  • -

#3 berserker7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-October 12

Re: Set elements of stack java

Posted 05 October 2012 - 04:54 PM

hi. but the answer for first example is correct for 100% becuase its a teacher example. I did not get the size of the stack. Also it doesnt say in which position x actually is. For these exercises I can use the stack 1 nd stack 2, push(s,d) pushes element 'd' onto the stack. there is one more example to solve: 'set x to the bottom, leave stack empty'.

pop(s),pop(s), x=peek(s), push(s,d), push(s,e), pop(s), pop(s), push(s,e),push(s,d)? is this answer better for second example?

pop(s),pop(s), x=peek(s), push(s,d), push(s,e), pop(s), pop(s), push(s,e),push(s,d)? is this answer better for second example?
Was This Post Helpful? 0
  • +
  • -

#4 berserker7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-October 12

Re: Set elements of stack java

Posted 07 October 2012 - 10:25 AM

Hi. If someone can close this topic? I have found some explanation. Dnt need ny more answer. thanks anyway
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1