![]() Similarly, there are two cases when adding a node to the tail of a doubly linked list. Set the new head’s previous pointer to null.Set the new head’s next pointer to the current head.Set the current head’s previous pointer to our new head.If there isn’t, then the list is empty, and we can simply make our new node both the head and tail of the list and set both pointers to null. When adding to the head of the doubly linked list, we first need to check if there is a current head to the list. In a doubly linked list, adding to the list is a little complicated as we have to keep track of and set the node’s previous pointer as well as update the tail of the list if necessary. Your home is the head of the list, your place of work is the tail, and every stop in between is another node in the list. Think of your daily commute on the subway as a real-world example of a doubly linked list. The head node’s previous pointer is set to null and the tail node’s next pointer is set to null. The head node is the node at the beginning of the list, and the tail node is the node at the end of the list. Each node contains data and two links (or pointers) to the next and previous nodes in the list. Like a singly linked list, a doubly linked list is comprised of a series of nodes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |