Suppose that we have a Stack s and Queue t-> Show the contents of both stacks af
ID: 3907696 • Letter: S
Question
Suppose that we have a Stack s and Queue t-> Show the contents of both stacks after each of the following statements:
top -- -- -- bottom
front -- -- -- back
s.push(1);
s:
t:
t.enqueue(2);
s:
t:
s.push(3);
s:
t:
t.enqueue(4);
s:
t:
s.push(t.dequeue());
s:
t:
s.push(t.front());
s:
t:
s.pop();
s:
t:
t.enqueue(s.peek());
s:
t:
s.push(t.dequeue());
s:
t:
t.enqueue(s.peek());
s:
t:
top -- -- -- bottom
front -- -- -- back
s.push(1);
s:
t:
t.enqueue(2);
s:
t:
s.push(3);
s:
t:
t.enqueue(4);
s:
t:
s.push(t.dequeue());
s:
t:
s.push(t.front());
s:
t:
s.pop();
s:
t:
t.enqueue(s.peek());
s:
t:
s.push(t.dequeue());
s:
t:
t.enqueue(s.peek());
s:
t:
Explanation / Answer
Hello Student!
I am happy to help you!
top ----- bottom
s.push(1);
s:1->NULL
t: -None-
t.enqueue(2);
s:1->NULL
t:NULL<-1
s.push(3);
s:3->1->NULL
t:NULL<-1
t.enqueue(4);
s:3->1->NULL
t:NULL<-1<-4
s.push(t.dequeue());
s:1->3->1->NULL
t:NULL<-4
s.push(t.front());
s:4->1->3->1->NULL
t:NULL<-4
s.pop();
s:1->3->1->NULL
t:NULL<-4
t.enqueue(s.peek());
s:1->3->1->NULL
t:NULL<-4<-1
s.push(t.dequeue());
s:4->1->3->1->NULL
t:NULL<-1
t.enqueue(s.peek());
s:4->1->3->1->NULL
t:NULL<-1<-4
Thank you. Feel free to ask anything. Please upvote, if you like the answer. Thank you again.
top ----- bottom
front---- backs.push(1);
s:1->NULL
t: -None-
t.enqueue(2);
s:1->NULL
t:NULL<-1
s.push(3);
s:3->1->NULL
t:NULL<-1
t.enqueue(4);
s:3->1->NULL
t:NULL<-1<-4
s.push(t.dequeue());
s:1->3->1->NULL
t:NULL<-4
s.push(t.front());
s:4->1->3->1->NULL
t:NULL<-4
s.pop();
s:1->3->1->NULL
t:NULL<-4
t.enqueue(s.peek());
s:1->3->1->NULL
t:NULL<-4<-1
s.push(t.dequeue());
s:4->1->3->1->NULL
t:NULL<-1
t.enqueue(s.peek());
s:4->1->3->1->NULL
t:NULL<-1<-4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.