Help linking new node at front of list C++ Hello, I have finished most of my cod
ID: 3712531 • Letter: H
Question
Help linking new node at front of list C++
Hello, I have finished most of my code, but in the main i have directions to link new node at the front of the list, set the next field of node to the beginning of the list (*list), and set the beginning of the list to node. I was wondering how to implement that? code is below
1 int main 3 Shape list; 4 read_objs (&list;); 5 print objs (list) 8 void read_objs (Shape tolist) 10 I variable used to create a new node each time through the loop Shape node double x, y, z, xx, yy, zz,, rad; // temporary variables used to read in values; fill in the rest 12 13 string type, color, color21/ temporary variables used to read in values; fill in the rest 14 15 16 17 18 19 // initialize list list NULL; while (cin type) if (type. compare ("sphere") = 0) { 21 cin >x >>y > z >> rad color node new Sphere(type, color, Point(x,y,z), rad) 24 25 26 else if (type.compare ("box)0) cin >xx yy > zz > x »y> z >> color color2; node new Box(type, color, color2, xx, yy, zz, Point(x,y,z)); 29 31 32 else if (type.compare ("cone"0) 35 cin >> x >> y >> z >> xx >> yy >> zz >> rad >> color >> color2; node= new Cone (type, color, color2, Point (x, y, z), Point (xx, yy, zz), rad); 39 41 42 43 // link new node at front of list: // set the next field of node to the beginning of the list (xlist) // set the beginning of the list to nodeExplanation / Answer
You an add the below code
if(*list ==NULL)
*list = node;
else{
node->next = *list;
*list = node;
}
NOTE:
Check if there is something called next pointer of node or link.
What is the variable name used , change accordingly
Thanks, PLEASE COMMENT if there is any concern. I will help
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.