Set elements of stack java

Page 1 of 1

3 Replies - 1609 Views - Last Post: 07 October 2012 - 10:25 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294395&amp;s=6f605e1edc386bf3ac6ff0af02ba45fc&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 berserker7

Reputation: 0
• 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.

Is This A Good Question/Topic? 0

Replies To: Set elements of stack java

#2 Kinaces

Reputation: 78
• 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?

#3 berserker7

Reputation: 0
• 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?

#4 berserker7

Reputation: 0
• 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