How would one go about deleting every single person (node) from a singly linked list which has the name Jack?
i.e.
Start:
Finish:Code:Jack -> John -> Ann -> Bill -> Jack -> Jack -> Frank -> Jack
Code:John -> Ann -> Bill -> Frank
How would one go about deleting every single person (node) from a singly linked list which has the name Jack?
i.e.
Start:
Finish:Code:Jack -> John -> Ann -> Bill -> Jack -> Jack -> Frank -> Jack
Code:John -> Ann -> Bill -> Frank
One way to do it:
Create a function that deletes a single node.
Create a function which finds a node by its name.
Find all desired nodes by name and then delete them.
To delete an entry in a linked list you can simply change the pointer of the previous entry to point to the next entry, then free the current entry.
If you had:
Jack -> John -> Ann
Then to delete John you'd do something like:
Code:temp = John; Jack->next = Ann; free( temp );
You want to do this faster than O(n)? Maybe you want to use hashing
I would like to avoid hashing. Not that I'm affraid of it, just want to do it the "normal" way using only that one linked list