0% found this document useful (0 votes)
942 views

Header Linked List

A header node is a special node found at the beginning of a header-linked list that stores the number of nodes, allowing the size to be easily obtained without traversal. There are two types of header-linked lists: grounded, where the last node contains a NULL pointer, and circular, where the last node points to the header node. Algorithms like traversal and searching can be performed on a circular header-linked list by starting at the header node.

Uploaded by

Ramya Shree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
942 views

Header Linked List

A header node is a special node found at the beginning of a header-linked list that stores the number of nodes, allowing the size to be easily obtained without traversal. There are two types of header-linked lists: grounded, where the last node contains a NULL pointer, and circular, where the last node points to the header node. Algorithms like traversal and searching can be performed on a circular header-linked list by starting at the header node.

Uploaded by

Ramya Shree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CHAPTER 1

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.

Structure –Header Linked List

struct node

int data;

struct node *next;

};

It has two types:

1) Grounded Header Linked List


2) Circular Header Linked List

1) Grounded Header Linked List


It is a list whose last node contains the NULL pointer. In the header linked list
the start pointer always points to the header node. start -> next = NULL indicates
that the grounded header linked list is empty. The operations that are possible on
this type of linked list are insertion, deletion, and traversing.

Page | 1
DEPT OF CSE, GECT
Header node

START N

Header Linked List

2) Circular Header Linked List


A list in which last node points back to the header node is called circular linked
list. The chains do not indicate first or last nodes. In this case, external pointers
provide a frame of reference because last node of a circular linked list does  not
contain the NULL pointer. The possible operations on this type of linked list
are insertion, deletion and traversing

Header node

START

Circular Linked List

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:

Traversing a Circular Header Linked List


Let LIST be circular header list in memory. This algorithm list traverses, applying an
operation process to each node of list.
1. Set PTR:=START LINK.[Initializes the pointer PTR]
2. Repeat steps 3 and 4 while PTR≠START:
3. Apply PROCESS to PTR INFO.
4. Set PTR : = PTR LINK..
5. Exit

Searching in Circular Header Linked List


SRCHHL(INFO,LINK,START,ITEM,LOC)
1. Set PTR=LINK[START]
2. Repeat while INFO[PTR]!=ITEM and PTR!=START
Set PTR=LINK[PTR]
3. If INFO[PTR]=ITEM ,then
Set LOC=PTR
Else Set LOC=NULL
4. EXIT

CHAPTER 2

C Program for a Header Linked List


#include <malloc.h>
#include<stdio.h>
// Structure of The list
struct link{
int info;
struct link*next;
};

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;

// If it is the first node


if(start==NULL) {

// Initiallize the start


start=(struct link*)
malloc (size of (structlink));
start->next=new_node;
}
else{

// Insert the node in the node=start;


while(node-> !=NULL)
node= node-.>next;
}
node->next=new_node;
}
return start;
}

// Function to display the


// header linked list

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);

// Print the list


display();
create_header_list(14);
create_header_list(15);

// Print the list


display();
return0;
}
Output:
11 12 13
11 12 13 14 15

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

1) Data Structures and Applications A.A.Puntambekar


2) E Baiaguruswamy

Page | 6
DEPT OF CSE, GECT

You might also like