I have a doubly linked list data structure that looks like the following:
Node structure is as follows:
typedef struct {
int32_t type;
int32_t valueint;
double valuedouble;
struct cNODE *next;
struct cNODE *prev;
struct cNODE *child;
} cNODE;
Each node has a child element which can point to another node/doubly linked list of the same element(node) type. Till now, I used the following code to delete this complete data structure:
/* Delete a cNODE structure. */
void cNODE_Delete(cNODE *c)
{
cNODE*next;
while (c)
{
next=c->next;
if (!(c->type)) && c->child)
{
cNODE_Delete(c->child)
};
free(c);
c=next;
}
}
But this is a recursive function. I have a certain requirement where I can't use recursion. Can this deletion be implemented without recursion? Any examples are appreciated.