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 ) ) ;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.