Question: As part of the development team at MumbleTech.com, Janet has written a list manipulation library for C that contains, among other things, the code in
As part of the development team at MumbleTech.com, Janet has written a list manipulation library for C that contains, among other things, the code in Figure 3.16.

(a) Accustomed to Java, new team member Brad includes the following code in the main loop of his program:

Sadly, after running for a while, Brad’s program always runs out of memory and crashes. Explain what’s going wrong.
(b) After Janet patiently explains the problem to him, Brad gives it another try:
This seems to solve the insufficient memory problem, but where the program used to produce correct results (before running out of memory), now its output is strangely corrupted, and Brad goes back to Janet for advice. What will she tell him this time?
typedef struct list_node { void* data; struct list_node* next; } list_node; list_node* insert (void* d, list_node* L) { list_node* t = (list_node*) malloc (sizeof (list_node)); t->data = d; t->next = L; %3D return t; list_node* reverse (list_node* L) { list_node* rtn = 0; while (L) { rtn = insert (L->data, rtn); L = L->next; return rtn; void delete_list (list_node* L) { while (L) { list_node* t = L; L = L->next; free (t->data); free(t);
Step by Step Solution
3.30 Rating (159 Votes )
There are 3 Steps involved in it
a The reverselist routine produces a new list composed of new list nodes When Brad assigns the retur... View full answer
Get step-by-step solutions from verified subject matter experts
