17
17
h>
#include <stdlib.h>
// Function to count the number of nodes in the circular doubly linked list
int countNodes(struct Node* head) {
if (head == NULL) return 0; // Empty list
int count = 0;
struct Node* temp = head;
do {
count++;
temp = temp->next;
} while (temp != head); // Stop when we return to the head
return count;
}
// User-defined input
printf("Enter the number of elements in the list: ");
scanf("%d", &n);
return 0;
}
-----------------------------------------------------------------------------------
----------
Test case:
Enter the number of elements in the list: 3
Enter the elements of the list:
13
23
14
Circular Doubly Linked List: 13 23 14
Number of nodes in the circular doubly linked list: 3