diff --git a/linkedlist b/linkedlist index b945c43..fb955bc 100755 Binary files a/linkedlist and b/linkedlist differ diff --git a/linkedlist.c b/linkedlist.c index b409442..e763263 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -41,3 +41,18 @@ 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 0ee14af..355103a 100644 --- a/linkedlist.h +++ b/linkedlist.h @@ -12,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 0b02371..24a434f 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,9 @@ int main() { printf("\nElement not found"); } + printf("\nTotal nodes = %d", count()); + return 0; + }