Statistics Help
Question: One of the applications of stack is to backtrack-that is to retrace its steps. As 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 discard and negative number.
Use a stack to solve this problem. Read the numbers and push them into the 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 than five items in the stack, print an error message and stop the program.
After printing the five items, resume reading data and placing them in the 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 1 2 3 4 5 6 7 8 9 10 -2 11 12 -3 1 2 3 4 5 Edit
TutorTeddy.com & Boston Predictive Analytics
[ Email your Statistics or Math problems to help@teddycan.com (camera phone photos are OK) ]
Boston Office (Near MIT/Kendall 'T'):
Cambridge Innovation Center,
One Broadway, 14th Floor,
Cambridge, MA 02142,
Phone: 617-395-8864
Dallas Office (Near Galleria):
15950 Dallas Parkway,
Suite 400,
Dallas, TX 75248,
Phone: 866-930-6363