Question: #include #include struct person { char *name; int age; struct person * next; // We've added a next pointer. }; struct person *front=NULL, *rear=NULL; //

 #include #include struct person { char *name; int age; struct person

* next; // We've added a "next" pointer. }; struct person *front=NULL,

#include #include

struct person { char *name; int age; struct person * next; // We've added a "next" pointer. };

struct person *front=NULL, *rear=NULL; // The usual front,rear pointers.

void print (struct person *p) { printf ("Name=%s age=%d ", p->name, p->age); }

struct person* makeNode (char* name, int age) { struct person *p; p = (struct person*) malloc (sizeof(struct person)); p->name = name; p->age = age; p->next = NULL; return p; }

void addToList (char* name, int age) { if (front == NULL) { front = makeNode (name, age); rear = front; } else { rear->next = makeNode (name, age); rear = rear->next; } }

void printList () { struct person *p;

// WRITE YOUR CODE HERE: use the pointer p // to walk down the list.

}

int main () { addToList ("R2-D2", 609); addToList ("Optimus Prime", 2700); addToList ("Wall-E", 210); printList (); }

Exercise 3.8: Copy/paste the above in linkedlistExample.c, including a complete printList) function, and fill in a complete memory diagram right after the three nodes are added to the list (only include heap addresses - use the debugger to find them)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!