Given two initially empty queues, queue1 and queue2 and the following commands.
ID: 3579957 • Letter: G
Question
Given two initially empty queues, queue1 and queue2 and the following commands.
queue1.addQueue(1)
queue1.addQueue(2)
queue2.addQueue(3)
queue1.addQueue(4)
queue1.deleteQueue()
queueFront = queue1.front()
queue1.addQueue(queueFront)
queue2.addQueue(5)
queue1.deleteQueue()
queue2.addQueue(7)
What is the sum of the contents of queue2?
4
15
19
none of these
Given the following queue operations on an empty existing queue called nameQueue.
nameQueue.addQueue(Alex)
nameQueue.addQueue(Gina)
nameQueue.deleteQueue()
nameQueue.addQueue(Bob)
nameQueue.addQueue(Susan)
nameQueue.deleteQueue()
display (Queue.front( )) //assuming that display function displays the string passed to it.
What name is displayed?
Alex
Gina
Bob
Susan
Front
Explanation / Answer
1) In Queue insertion happens at rear and deletion happens from front as it follows FIFO (first in first out)
Hence after belwo instruction
queue1.addQueue(1) - 1
queue1.addQueue(2) - 1,2
queue1.addQueue(3) - 1,2,3
queue1.addQueue(4) -1,2,3,4
we have now
1
2
3
4
queue1.deleteQueue()
so it will delete from front which is 1, hence now queue becomes
2
3
4
Now queue front is 2
queueFront = queue1.front() so queueFront will have 2
Now queue1.addQueue(queueFront), queue becomes
2
3
4
2
queue2.addQueue(5), its adding in a different queue so queue2 becomes
5
queue1.deleteQueue(), this deletes front element from queue 1 which means 2 now queue becomes
3
4
2
queue2.addQueue(7), it will add 7 to rear of queue 2 and now queue2 becomes
5
7
Sum of the contents of queue 2 is 5+7 which is 12, none of the given option.
1
2
3
4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.