diff --git a/linkedlist b/linkedlist index 94affb9..8079aa9 100755 Binary files a/linkedlist and b/linkedlist differ diff --git a/linkedlist.c b/linkedlist.c index 6ba7cc7..98e5330 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -41,3 +41,17 @@ int search(int value) return 0; } + +int count() +{ + int count = 0; + Node *temp = head; + + while (temp != NULL) + { + count++; + temp = temp->next; + } + + return count; +} diff --git a/linkedlist.h b/linkedlist.h index 9582cc6..dd1d311 100644 --- a/linkedlist.h +++ b/linkedlist.h @@ -1,3 +1,4 @@ + #ifndef LINKEDLIST_H #define LINKEDLIST_H @@ -11,5 +12,6 @@ typedef struct Node void insert(int data); void display(); int search(int value); +int count(); #endif diff --git a/main.c b/main.c index a3d92ae..cd72d58 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,7 @@ if (search(20)) { printf("\nElement not found\n"); } + printf("Total nodes = %d\n", count()); return 0; }