Write a function to delete a Linked List Algorithm: Iterate through the linked list and delete all the nodes one by one. Main point here is not to access next of the current pointer if current pointer is deleted. Implementation: #include
#include #include /* Link list node */ struct node { int data; struct node* next; }; /* Function to delete the entire linked list */ void deleteList(struct node** head_ref) { /* deref head_ref to get the real head */ struct node* current = *head_ref; struct node* next; while (current != NULL) { next = current->next; free(current);
Read full article from Write a function to delete a Linked List | GeeksforGeeks
No comments:
Post a Comment