Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Decimal equivalent of binary linked list

Write an efficient algorithm to Convert Decimal equivalent of binary linked list.

Example

Formula

Visit every node of linked list from head to last node. And applying this formula to get the decimal result of single pass of given linked list.

Function

Given linked list contain following nodes [0 1 0 0 0 1 ].

root_ptr100010

Result : 17

View Nodes and pointer.

Stack Areamainroot(pointer) Heap Areastruct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 1next (pointer)= NULL

Try it Yourself

Program for convert binary linked list to decimal equivalent of given linked list.

Output

Visualize process.

Stack Areamainroot(pointer)decimalresult (int) =17root(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 0next (pointer) struct Nodedata (int)= 1next (pointer)= NULL

Try it Yourself

Spread the post

Recommended Posts: