Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am looking at my teacher\'s example code of a linked list and am not sure what

ID: 3733560 • Letter: I

Question

I am looking at my teacher's example code of a linked list and am not sure what is happening within lines 68 & 70 on the bottom picture. So he allocated memory for a pointer that's an object pointing to the structure Link? Is the function "Link *fillList(int n)" an object of that same class as well that is returning the address of the news node made?

Header file

#ifndef LINK H - #define LINK //Composition of a Link struct Link 0: #endif /* LINK-H */ int data; Link *linkPtr //Self Reference which when utilized forms a linked list //Any integer data, to be changed any class with templates later

Explanation / Answer

your code implements linked lists with structure only, do not bring classes in between and get confused.
the line Link *front =new Link allocates memory of type Link, i.e memory to hold one variable of link structure, and it returns a pointer to that newly allocated memory, which we are calling front here. The word Link in front of *front denotes that front points to an address that holds a structure variable of Link
the line Link *fillLst(int n) means that it takes int n as a parameter and the astrisk in front of it denotes that the function returns a pointer. A pointer of what kind? That is answered by the Link in the beginning which clarifies that the pointer that is returned points to a variable of Link type