We are ready to put everything together! Rather than simply storing three points that were already known at compile time, we’ll now ask the user to enter the number of points they wish to store and then create space in memory at run-time for each such point. Each newly created point (other than the first one, which is the start of the list), is linked to the list by saving its address at the previous element of the list.
If you cannot see this codecast, please click here.
Check Your UnderstandingCheck Your Understanding
1.
You’d like to print all of the names of students whose records are stored in a linked list. As before, each student record is stored as
Which of the following is true about the above function?
The function doesn’t print the name of the last student in the list if the list is nonempty.
Correct
The function is implemented incorrectly because it changes start.
Not quite. Try again!
The function will print a random name when the list is empty.
Not quite. Try again!
2.
Suppose you wanted to delete the third student in a linked list of five student records. Why can’t you just free the space allocated for the third student?
By deleting the third student you’d loose access to the remaining students in the list. Instead, you’d need to link the second student to the fourth student in the list (and in order to do so, you need to know where the third student was pointing).
Correct
The compiler won’t let you do that.
Not quite. Try again!
It is impossible to delete a student from a linked list of students. That’s why arrays are better than linked lists.
Not quite. Try again!
You need to use the command free instead of simply deleting the student. As long as you use free you are okay.