Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

How do economists try to disentangle cause and effect? Discuss.

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago