Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a flow chart of the steps in making this program in terms how each pointer's element changes. /* This program creates a linked list

Create a flow chart of the steps in making this program in terms how each pointer's element changes.

/* 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); } 
Enter a tree name (END to finish): Palm Enter a tree name (enter end to finish): Cedar Enter a tree name (enter end to finish): Elm Enter a tree name (enter end to finish): Oak Enter a tree name (enter end to finish): Spruce Enter a tree name (enter end to finish): Fir Enter a tree name (enter end to finish): Cherry Enter a tree name (enter end to finish): END Cherry Fir Spruce Oak Elm Cedar Palm

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

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

Identify five strategies to prevent workplace bullying.

Answered: 1 week ago