0
Can you help me please?
Given a 5 element queue Q (from front to back: 1, 3, 5, 7, 9), and an empty stack S, remove the elements one-by-one from Q and insert them into S, then remove them one- by-one from S and re-insert them into Q, show the order of elements?
2 odpowiedzi
+ 2
While Q is not empty:
S.push(Q.pop())
While S is not empty:
Q.push(S.pop())
final order : 9 7 5 3 1
+ 1
Here are two articles that talk about the queue interface and stack class .
https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.geeksforgeeks.org/stack-class-in-java/amp/&ved=2ahUKEwjM5L6siqjvAhWvzTgGHRewD2QQFjAAegQIARAC&usg=AOvVaw3yx3MARfBmhRM02kTDmj7F&cf=1&cshid=1615460405940
https://www.geeksforgeeks.org/queue-interface-java/amp/