Given a singly linked list of 0s and 1s find its decimal equivalent.
Input : 0->0->0->1->1->0->0->1->0 Output : 50 Input : 1->0->0 Output : 4
Decimal Value of an empty linked list is considered as 0.
Initialize result as 0. Traverse the linked list and for each node, multiply the result by 2 and add node’s data to it.
Decimal value is 11
This article is contributed by Shivam Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Binary Search on Singly Linked List
- Flatten a binary tree into linked list
- Flatten a binary tree into linked list | Set-3
- Flatten a binary tree into linked list | Set-2
- Convert a given Binary Tree to Doubly Linked List | Set 4
- Convert a given Binary Tree to Doubly Linked List | Set 2
- Convert a given Binary Tree to Doubly Linked List | Set 3
- Convert a given Binary Tree to Doubly Linked List | Set 1
- Create a sorted linked list from the given Binary Tree
- Extract Leaves of a Binary Tree in a Doubly Linked List
- Convert a given Binary Tree to Circular Doubly Linked List | Set 2
- Create new linked list from two given linked list with greater element at each node
- Merge a linked list into another linked list at alternate positions
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Difference between Singly linked list and Doubly linked list
- Convert singly linked list into circular linked list
- Convert Singly Linked List to XOR Linked List
- Check if a linked list is Circular Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes