Spread the post

Print multilevel linked list to vertical order

Given a multilevel linked list, print all nodes in vertical order form of left to right and top to bottom. note that this multi-level linked list has two pointer next and down. that are contain or bind the linked list nodes. view the structure of linked list.

view input and accepted outputs

12345786101112913

Print node left to right and top to bottom vertical order.

12345786101112913

Hint : solve this program using queue. view linked list.

Stack Areamainroot(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) down (pointer) struct Nodedata (int)= 2next (pointer) down (pointer)= NULLstruct Nodedata (int)= 3next (pointer) down (pointer)= NULLstruct Nodedata (int)= 4next (pointer)= NULLdown (pointer) struct Nodedata (int)= 5next (pointer) down (pointer)= NULLstruct Nodedata (int)= 6next (pointer)= NULLdown (pointer) struct Nodedata (int)= 10next (pointer)= NULLdown (pointer)= NULLstruct Nodedata (int)= 7next (pointer) down (pointer) struct Nodedata (int)= 8next (pointer) down (pointer)= NULLstruct Nodedata (int)= 9next (pointer)= NULLdown (pointer)= NULLstruct Nodedata (int)= 11next (pointer) down (pointer) struct Nodedata (int)= 12next (pointer)= NULLdown (pointer)= NULLstruct Nodedata (int)= 13next (pointer)= NULLdown (pointer)= NULL

program to print multi-level linked list to vertical order. Time complexity O(n).

Output

View process.

Stack Areamainroot(pointer) NULLvertical_printauxiliary(pointer)head(pointer)root(pointer)tail(pointer)temp(pointer)enqueuenew_node(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 8next (pointer) down (pointer)= NULLstruct Nodedata (int)= 9next (pointer)= NULLdown (pointer)= NULLstruct Nodedata (int)= 11next (pointer) down (pointer) struct Nodedata (int)= 12next (pointer)= NULLdown (pointer)= NULLstruct Nodedata (int)= 13next (pointer)= NULLdown (pointer)= NULLstruct Queuelink (pointer) next (pointer)= NULLstruct Queuelink (pointer) next (pointer)= NULL

View steps of execution

Submit your solution in comment section.

Spread the post

Recommended Posts: