Use stacks to solve this problem.Read the numbers and push them into the stack u
ID: 3650029 • Letter: U
Question
Use stacks to solve this problem.Read the numbers and push them into the stack until a negative number is read.At this time,stop reading and pop five items from stack and print them.If there are fewer than five items in the stack ,print error message and stop the program.After printing the five items resume reading and placing them in stack.When the end of file is detected,print a
message and the items remaining in the stack.
Test with this data
1 2 3 4 5 -1 1 2 3 4 5 6 7 8 9 10 -2 11 12 -3 1 2
Explanation / Answer
Stack followins LIFO order i.e. last in first out and it is useful for expression conversiona and evaluation and queue follows FIFI order i.e. first in first out
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.