Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Find and search linked list data

root pointer are pointed to first node of given linked list. we know that about the can be access all other nodes a help of root pointer.the following process to find linked list node data.

1) assign root node value to temp pointer.


because we are not modificated original value of root pointer;

2) using while loop visiting all other linked list node. if temp->data value is equal to find_data. that means find_data are exist. otherwise move next node of linked list. if status variable are 0. and temp->next=NULL that means find data are not exist.

Assume that following data [1,2,3,4,5,6,7] are inserted on linked list.

find & search linked list node

View insertion process to linked list.

Try it yourself


Search linked list node data [6]


Search data [3]



Time complexity of this algorithm O(n).

Code Execution:

Stack Areamainroot(pointer)search_datafind_data (int) =5status (int) =1temp(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 7next (pointer)= NULL

Not given all step of execution process here.View How to insert linked list element, how to print and so on.

Try it yourself

c program to find given linked list data exist or not. Iterative approach.

 Case 1: Empty Linked list 
  Empty linked List

 case 2: When linked list are not empty 
 linked list :1  2  3  4  5  6  7  
 Given data [5] are exist
 Given data [3] are exist
 Given data [7] are exist
 Given data [9] are note exist

 Free nodes of linked linked 

Spread the post