Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Wednesday, April 12
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw31and submit using the
- This is an electronic homework and you do not need to print out anything to turn in during class.
- Required reading: Sections 1 (Intro) and 2 (Creating linked lists) from the Unit 9 notes.
Write a program called
back3.cthat reads in ints from the user until a negative number is entered, storing them into a linked list. Then print out the 3rd-to-last number that was entered. (You can assume that at least 3 numbers will always be entered before a negative.)
Hint: Store the numbers in your linked list in reverse order by calling
add2frontrepeatedly as you read each number in.
Hint 2: Don't hesitate to draw a picture of some small examples, like with five or six numbers, to understand and check your code!
1 2 3 4 5 6 7 8 9 -1
4 8 2 7 4 9 -1
15 16 17 -1