Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C-Code Implement delAll which will go through the whole data structure pointed t

ID: 644971 • Letter: C

Question

C-Code

Implement delAll which will go through the whole data structure pointed to by root and delete it correctly. You should not access freed heap contents so the order of deleting matters. Write your recursive solution as consise and cleas as possible. you do not need helpter functions.

typedef struct keyNodeStruct{

char *key;

valueNode *values;

struct keyNodeStruct *next;

}keyNode;

typedef struct valueNodeStruct {

char *value;

struct valueNodeStruct *next;

}valueNode;

void delAll(tree *root) { // Recursion

Explanation / Answer

since the question does not mention what is to be copied where, i shall write the program to copy from key node to value node

typedef struct keyNodeStruct

{char *key;

valueNode *values;

struct keyNodeStruct *next;

}keyNode;

typedef struct valueNodeStruct {

char *value;

struct valueNodeStruct *next;

}valueNode;

  

void copyall ( struct node *q, struct node **s )
{
if ( q != NULL )
{
*s = malloc ( sizeof ( struct node ) ) ;
( *s ) -> data = q -> data ;
( *s ) -> link = NULL ;
copy ( q -> link, &( ( *s ) -> link ) ) ;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote