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?

11th Mar 2021, 9:40 AM
Rahima Mirzad
Rahima Mirzad - avatar
2 Antworten
+ 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
11th Mar 2021, 11:55 AM
deleted