Section 27.3 Automate the Linking Process
We’ll continue working with our linked list of points in the next video. This time we’ll learn how to automate the linking process between the points with the help of a function.
If you cannot see this codecast, please click here .
Video Description.
Functions can be used to link one point to another point
Functions can be used to add on (append) a new element to an existing list
Whole lists are created by repeatedly appending a new element to the previous end of the list
i.e. call a function, pass to it the current end of the list and the element to be appended, create the link inside the function and return the new end of the list (which is the element that was just added on)
Check Your Understanding Check Your Understanding
1.
Given the structure definition from the video,
struct point{
int x;
int y;
struct point * next;
};
what is the return type of the following function:
struct point * append (struct point * end, struct point * newpt) {
end->next = newpt;
return(end->next);
}
a pointer to an object of type
struct student
Correct
an object of type
struct student
Not quite. Try again!
Not quite. Try again!
Not quite. Try again!