Circular Linked List
Circular Linked list is data structure used for storing collections of data. It has following features.
* Each item in the list points to next item and previous item.
* Last item points to first item of the list.
* There will be no NULL pointer
* It can grow or shrink during execution of a program.
* There is no wastage of memory space.
* Can be made just as long as required.
Circular Linked list::
declaration:
struct trynode{
int data;
struct trynode *ptr_to_node;
};
typedef struct trynode* NODE;
data will hold the actual data of the each node and
ptr_to_node points to next item in the linked list.
Function to count the no of elements in the linked list
int CirculrList(NODE first)
{
NODE cur;
if(first==NULL) return 0;
cur=first;
do{
count++;
cur=cur->ptr_to_node;
}while(cur->ptr_to_node!=first);
return count;
}
Circular Linked list is data structure used for storing collections of data. It has following features.
* Each item in the list points to next item and previous item.
* Last item points to first item of the list.
* There will be no NULL pointer
* It can grow or shrink during execution of a program.
* There is no wastage of memory space.
* Can be made just as long as required.
Circular Linked list::
declaration:
struct trynode{
int data;
struct trynode *ptr_to_node;
};
typedef struct trynode* NODE;
data will hold the actual data of the each node and
ptr_to_node points to next item in the linked list.
Function to count the no of elements in the linked list
int CirculrList(NODE first)
{
NODE cur;
if(first==NULL) return 0;
cur=first;
do{
count++;
cur=cur->ptr_to_node;
}while(cur->ptr_to_node!=first);
return count;
}
No comments:
Post a Comment