Below , there is a function for inserting data into a node of a circular list. Can u please help me create a delete function for the circular list by providing some code? Also, can you provide some code for traversing the circular list? Thanks in advance
staticvoid push(node *head, int v)
{
node *temp = (node*)malloc(sizeof(node));
temp->val = v;
temp->next = head;
head = temp;
}
/* Deleting node 'head' is difficult because we have no direct access to its predecessor.
* But it's easy deleting the successor, so I go this way.
*/
staticvoid del( node *head)
{
if (head == nullptr) return; // list is empty
if (head == head->next)
{
free(head); // the list have only one element
head == nullptr;
return;
}
node *tmp = head->next; // will get deleted
head->next = head->next->next;
free(tmp);
}
static node* next( node *head)
{
// using the ternary conditional
return head == nullptr ? nullptr : head->next;
}