Create Circular linked list
- create a node template with the basic code given below.
*next pointer hs address of the next node for the actual current node.
2.use typedef keyword to create an alias name for structure cll (data type).here in the below code new datatype known as node is created using the typedef keyword
- write a function for creating a newnode using malloc function and taking node data value from the user with in the function
In the above code getnode() function returns the node type of pointer, it returns the newnode from the function .when the getnode function is called in the program this creates a node in the memory.
4.create a *head pointer and assign NULL
- create two more pointers known as *newnode,*temp inside createnodes function, use FOR loop for condition (i<no of nodes).
6.call getnode( ) function for the newnode pointer ,inside for loop
- create a if block for condtion (head==NULL) then assign newnode to the head
for the else block
- to add next nodes, initialize temp with a head pointer
use while condition (temp->next!=NULL),so that the temp will be at the last or if there is only one node the temp pointer will be there in the first place
if there are more then one nodes,this while condition is useful ,inside while loop change temp from one node to next node until it points to last node
10.link next address of temp node to newnode (temp -> next = newnode)
11.after the for loop,link last node next address to the head node ,the last node will be newnode (newnode ->next = head)
12.last node is pointing to starting node,this is circular list
Program to Create Circular linked list
Traverse Circular linked list
- create a *temp pointer from node structure, initialize this temp pointer with head
- move temp pointer to next node in linked list ,move temp pointer by replacing next nodes address (temp=temp->next ) until the condition (temp!=head)
3.display each node’s data