diff --git a/linkedlist b/linkedlist index 8079aa9..7c926d1 100755 Binary files a/linkedlist and b/linkedlist differ diff --git a/linkedlist.c b/linkedlist.c index 98e5330..5e03c01 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -25,7 +25,7 @@ void display() } } -int search(int value) +Node *search(int value) { Node *temp = head; @@ -33,13 +33,13 @@ int search(int value) { if (temp->data == value) { - return 1; + return temp; } temp = temp->next; } - return 0; + return NULL; } int count() diff --git a/linkedlist.h b/linkedlist.h index dd1d311..a0dac39 100644 --- a/linkedlist.h +++ b/linkedlist.h @@ -11,7 +11,7 @@ typedef struct Node void insert(int data); void display(); -int search(int value); +Node *search(int value); int count(); #endif diff --git a/main.c b/main.c index cd72d58..3bdac78 100644 --- a/main.c +++ b/main.c @@ -6,18 +6,21 @@ int main() insert(10); insert(20); insert(30); + printf("Linked List: "); display(); -if (search(20)) +Node *result = search(20); + if (result != NULL) { - printf("\nElement found\n"); + printf("\nElement found: %d\n", result->data); } else { printf("\nElement not found\n"); } - printf("Total nodes = %d\n", count()); + + printf("Total nodes = %d\n", count()); return 0; }