In: Computer Science
Assume you have a stack and a queue implemented using an array of size 4. show the content of the array for the stack (then the queue) for the following operations: (for the queue replace push by add and pop by remove; keep in mind that the queue uses a circular array): push(-3), push(-5), push(-9), push(-10), pop(), pop(), push(-13), pop(), push( -15), push(-17).
java code
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
push(-3) stack would be -3
push(-5) stack would be -3 -5
push(-9) stack would be -3 -5 -9
push(-10) stack would be -3 -5 -9 -10
pop() stack would be -3 -5 -9
pop() stack would be -3 -5
push(-13) stack would be -3 -5 -13
pop() stack would be -3 -5
push( -15) stack would be -3 -5 -15
push(-17). stack would be -3 -5 -15 -17
Hence stack would be like below from top to bottom
-17
-15
-5
-3
add(-3) queue would be -3
add(-5) queue would be -3 -5
add(-9) queue would be -3 -5 -9
add(-10) queue would be -3 -5 -9 -10
remove() queue would be -5 -9 -10
remove() queue would be -9 -10
add(-13) queue would be -9 -10 -13
remove() queue would be -10 -13
add( -15) queue would be -10 -13 -15
add(-17). queue would be -10 -13 -15 -17
Hence queue would be like below from head to tail
-10
-13
-15
-17