Header Linked List
Header Linked List
INTRODUCTION
A header node is a special node that is found at the beginning of the list. A list that
contains this type of node, is called the header-linked list. This type of list is useful
when information other than that found in each node is needed. This special node is
used to store number of nodes present in the linked list. In other liked list variant, if
we want to know the size of the linked list we use traversal method. But in header
linked list, the size of the linked list is stored in its header itself.
struct node
int data;
};
Page | 1
DEPT OF CSE, GECT
Header node
START N
Header node
START
Observe that the list pointer START always points to the header node.
If START LINK=NULL indicates that a ground header list is empty.
If START LINK=START indicates that a circular header list is empty.
Page | 2
DEPT OF CSE, GECT
Algorithm:
CHAPTER 2
Page | 3
DEPT OF CSE, GECT
// Empty List
struct link*start =NULL;
// Function to create a header linked list
struct link* create_header_list(int data)
{
// Create a new node
struct link *new _node, *node;
new_node =(struct link*)
malloc(size of (struct link));
new_node->info =data;
new_node->next=NULL;
Page | 4
DEPT OF CSE, GECT
struct link*display()
{
struct link* node;
node=start;
node= node-> next;
while (node !=NULL) {
printf(“%d”,node->info)
node=node->next;
}
print f(“\n”);
return start;
}
// Driver code
int main()
{
// Create the list
create_header _list(11);
create_header_list(12);
create_header_list(13);
Page | 5
DEPT OF CSE, GECT
Benefits of using Header linked Lists
1) One way to simplify insertion and deletion is never to insert an item before the first or
after the last item and never to delete the first node.
2) You can set a header node at the beginning of the list containing a value smaller than
the smallest value in the data set.
3) You can set a trailer node at the end of the list containing a value larger than largest
value in the data set.
4) These two nodes, header and trailer, serve merely to simplify the insertion and deletion
algorithms and are not part of the actual list.
5) The actual list is between these two nodes.
CONCLUSION
A header linked list is one of the variant of linked list. In Header linked list, we have a
special node present at the beginning of the linked list. This special node is used to store
number of nodes present in the linked list. In other linked list variant, if we want to know
the size of linked list we use traversal method. But in Header linked list, the size of the
linked list is stored in its header itself. Usually, a list is always traversed to find the current
length is maintained in an additional header node that information can be easily obtained.
REFERENCES
Page | 6
DEPT OF CSE, GECT