Singly Linked List Searching Operation, Search function/algorithm

Searching:- To find a given item into Singly Linked List is known as Searching. when searching is successful then it will provide location or position of the node Otherwise, it will return null value.
सर्चिंग:- लिंक्ड लिस्ट में किसी दिए गए आइटम (मान) को खोजना, सर्चिंग कहलाता है। जब सर्चिंग संक्रिया सफल होती है, तब उस नोड की लोकेशन या पोजीशन प्रदान की जाती है अन्यथा नल वैल्यू रिटर्न की जाती है।

Let Assume that SLL was previously created by createsll() and start pointing to the first node of SLL and item is given in input by user.
माना कि createsll() द्वारा  SLL तैयार की गयी है, जिसके प्रथम नोड का एड्रेस स्टार्ट नामक पॉइंटर वेरिएबल में रखा गया है एवं आइटम यूजर द्वारा इनपुट के रूप में दिया गया है  

//Searching in SLL
void searchsll(int item){
NODE *temp=start;
int i=0;
clrscr();
if(temp==NULL){
printf("Linked list is not  Exist\n");
getch();
return;
}
while(temp!=NULL){i++;
if(item==temp->info){
printf("%d is Found\nNode Number=%d\n info part= %d\nLink Part=%u\n",item,i,temp->info,temp->link);
getch();
return;
}
temp=temp->link;
}
printf("%d is not found in SLL\n",item);
getch();
return;
}

No comments:

Post a Comment

Stack Data Structure, Push, Pop and Peek Operations , Applications of Stack

Stack is a linear data structure. It is collection of ordered data elements. It is also known as LIFO system (last in first out). It means i...