C/C++: how to clear a linked circular list
In the case of linked circular list you need to add some checks to avoid memory corruption.
Full example (compiled OK with GCC 8.x)
#include <iostream>
#include <cstdlib>
struct Node
{
Node(Node* prev, int val)
: prev(prev), next(NULL), value(val)
{ }
Node *prev, *next;
int value;
};
void clear_list(Node …