C Programming Code Examples C > Linked Lists Code Examples C Program to Search for an Element in the Linked List using Recursion C Program to Search for an Element in the Linked List using Recursion This C Program uses recursive function & search for an element in a linked list. A linked list is an ordered set of data elements, each containing a link to its successor. #include <stdio.h> #include <stdlib.h> struct node { int a; struct node *next; }; void generate(struct node **, int); void search(struct node *, int, int); void delete(struct node **); int main() { struct node *head; int key, number; printf("Enter the number of nodes: "); scanf("%d", &number); generate(&head, number); printf("\nEnter key to search: "); scanf("%d", &key); search(head, key, number); delete(&head); } void generate(struct node **head, int number) { int i; struct node *temp; for (i = 0; i < number; i++) { temp = (struct node *)malloc(sizeof(struct node)); temp->a = rand() % number; printf("%d ", temp->a); if (*head == NULL) { *head = temp; (*head)->next = NULL; } else { temp->next = *head; *head = temp; } } } void search(struct node *head, int key, int index) { if (head->a == key) { printf("Key found at Position: %d\n", index); } if (head->next == NULL) { return; } search(head->next, key, index - 1); } void delete(struct node **head) { struct node *temp; while (*head != NULL) { temp = *head; *head = (*head)->next; free(temp); } }