PROVIDE PYHTON SOURCE CODE WITH OUTPUT One of the application of stack is to backtrack. As an example , imagine we want to read a list of items and each time we read a negative number we must...


PROVIDE PYHTON SOURCE CODE WITH OUTPUT


One of the application of stack is to backtrack. As an example , imagine we want to read a list of items and each time we read a negative number we must backtrack and print the five numbers that come before the negative number and then discards the negative number. Use stack to solve the problem using python. Read the numbers and push them into stack(without printing them)until a negative number is read. At this time stop reading and pop five items from the stack and print them.If there are fewer items in the stack, print an error message and stop the program. After printing the five items resume reading data and placing them into stack. When the end of the file is detected print a message and the items remaining in the stack. Test your program with the following data:1 2 3 4 5  -1  10 20 30  -2  40 50 60 70 80



Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here