Explain Header Nodes With Example in Data Structure.
Header Nodes
If you want to delete item x, then we set current to be node prior to x and then have current’s next reference by pass x.
If you are trying to delete 1st element it becomes a special case
Special cases are always problematic in algorithm design and frequently leads to bugs in the code.
It is generally preferable to write code that avoids special cases.
One way to do that here is to introduce the header node
A header node is an extra node in the linked list that holds no data serves to satisfies the requirement that every node that contains an item have a previous node in the list
Moving to the front now means setting the current position to header node,and so-on, with a header node, a list is empty then header.next is null.
Labels: Data Structure