Question: Look at this example program. Write a similar program that will create such a dynamic linked list using a structure that stores cars (make, model,

Look at this example program. Write a similar program that will create such a dynamic linked list using a structure that stores cars (make, model, color, year). Write then a function that will print the list of all the yellow cars newer than 2010.

/* This program creates a linked list of tree names. Each node contains the name of the tree and a pointer to the next tree. Nodes are dynamically allocated and are displayed in reverse order. */

#include  #include  #include  #define NL 20 typedef struct tree { char tree_name [NL]; struct tree* next; }tree; int main (void) { /* temporary hold for tree name */ char name[NL]; /* declaring the starting and traveling pointers */ tree *p, *start; /* list is empty at the beginning */ start = NULL; /* enter first tree name (or END) */ printf ("Enter a tree name (END to finish): "); fgets (name,sizeof(name),stdin); treename[strlen(treename)-1] = '\0'; /* add tree name to the list and keep asking for more until END */ while (strcmp (name, "END") != 0) { /* allocate new node to hold new tree */ p = (tree *) calloc (1, sizeof(tree)); /* put tree name into new node */ strcpy (p -> tree_name, name); /* puts pointer to previous tree into pointer element */ p -> next = start; /* updates start pointer with new tree */ start = p; printf ("Enter a tree name (enter end to finish): "); fgets (name,sizeof(name),stdin); treename[strlen(treename)-1] = '\0'; } /* displays list of tree in reverse order */ p = start; while (p != NULL) { printf ("%s ", p -> tree_name); p = p -> next; } return (0); } 

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!