Given a doubly linked list, the task is to find the size of that doubly linked list. For example, size of below linked list is 4.
A doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes.
Traversal of a doubly linked list can be in either direction. In fact, the direction of traversal can change many times, if desired.
For example the function should return 3 for the above doubly linked list.
1) Initialize size to 0.
2) Initialize a node pointer, temp = head.
3) Do following while temp is not NULL
……a) temp = temp -> next
4) Return size.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Difference between Singly linked list and Doubly linked list
- Reverse a doubly linked list in groups of given size
- Construct a Doubly linked linked list from 2D Matrix
- Find pairs with given sum in doubly linked list
- Find the largest node in Doubly linked list
- Find pairs with given product in a sorted Doubly Linked List
- Memory efficient doubly linked list
- Reverse a Doubly Linked List
- Delete a node in a Doubly Linked List
- Convert a given Binary Tree to Doubly Linked List | Set 1
- QuickSort on Doubly Linked List
- Convert a given Binary Tree to Doubly Linked List | Set 2
- Extract Leaves of a Binary Tree in a Doubly Linked List
- Convert a given Binary Tree to Doubly Linked List | Set 3
- Merge Sort for Doubly Linked List
- Convert a given Binary Tree to Doubly Linked List | Set 4
- Convert a Binary Tree into Doubly Linked List in spiral fashion
- Create a Doubly Linked List from a Ternary Tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.