java - Stack and Queue (reading code) -


I want to sort this problem without putting it into Java IDE. (If it comes in an examination then I will not be able to solve it.)

So what I still know

I know that the stack is known as the envelope and the queue is known as FIFA, but I do not know how this code will pop out (or if I am right) < / P>

  public static zero main (string [] args) {line & lt; String & gt; Q = new line & lt; String & gt; (); Q.enqueue ("A"); Q.enqueue ("two"); Q.enqueue ("four"); Q.enqueue ("six"); String s = ""; Int i = 0; While (! Q.isEmpty ()) {s = s + q.dequeue () Substring (i); I ++; } STOOT Print (s); }   

Since this is a line, it will be fifo and the reason for the sub-object output will be: onewour?

And finally I got two problems in the Princeton CS class but I do not know how the answer came.

P>

Suppose that a client (queue) Intermitted sequence does. The enque operation has an integer number from 0 to 9 in the order on the queue; Deku Operations prints return value. Which of the following sequences can not be?

  (a) 0 1 2 3 4 5 6 7 8 9 (b) 4 6 8 7 5 3 2 9 0 (c) 2 5 6 7 4 8 9 3 1 0 (D Answer: (B), (C), and (D). 4 3 2 1 0 5 6 7 8 9.  

Assume that an intermediate sequence of (stack) push and pop operations is done. Push in the sequence from integer 0 to 9; Pops returns return value. Which of the following sequence can not be?

  (a) 4 3 2 1 9 8 7 6 5 (b) 4 6 8 7 5 3 2 9 0 (c) 2 5 6 7 4 8 9 3 1 0 (D ) 4 3 2 1 0 5 6 7 8 9 (E) 1 2 3 4 5 6 9 8 7 0 (F) 0 4 6 5 3 8 1 7 2 9 (G) 1 4 7 8 6 5 3 2 2 (H) 2 1 4 3 6 5 8 7 9   

Answer: (b), (f), and (g < P>

question 3)

look at B

4 6 8 7 5 3 2 9 0

When it was popped and 9 printed, it means that all push operations were finished at the time
(0,1, ..., 9) respectively Okay, now it's reading 9. So it is reading 0, that means it is reading the first number that has ever been pushed onto the stack.
Then there is no way which can pop and print it because it is already slipping the last / possible number (after 1 no way is dashed because 0 was popped because as it was said Was - all push operations were done 9 times in the popped time).

You need to use equally why to look at logical observations, f) and G) are not even possible. When reading all the scenes of the pop - try to visualize sequence only, which is between pop (i.e. the last pop that was pushed afterwards).
Any sort of pop is hiccups: it is not possible, it can not be so.

Question 2) It is a trivial, anything but A) is not possible. right?
Because with a queue in a shop, customers are served in the order in which they come to the cash desk. Otherwise it will not be queued

Question 1) If you actually type it, you will know it further, compile it and run it.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -