Homework 40

Write a program that uses a linked list to print out an entire list of numbers (of unknown length) collected from the user. For example, the user might enter a total of 10, 1983, or 2009 numbers, you canít know for sure ahead of time.Each new node should be added to the front of the linked list as it is being created. You must define and use a print function to print out the linked list. After you have printed the list, print the last number read and the next to the last number read (not including the 0). Here's an example of what a run of your program should look like (user input in red):

 

Enter a list of positive numbers, terminated by zero:
3 8 2 9 1 4 0
You entered:
4 1 9 2 8 3
The last number read was 4
The next to the last number read was 1

Note that adding to the front of the list naturally reverses the order of the numbers entered ... which is fine for this problem. As you think about how to solve this problem we advise you to 1) draw pictures and 2) write the looping condition last, not first.

Turn In a screen capture of your program running on the above sample input, and a printout of your source code.