Binary Search Tree | Find inorder traversal of a BST and convert to a linked list | BinarySearch.io

preview_player
Показать описание
Given a binary search tree root, convert it to a singly linked list using an in-order traversal. An in-order traversal of a node recursively visits the in-order of its left subtree, then visits the current node, and then recursively visits the in-order of its right subtree.

For example, given node

2
/ \
1 4
/ \
3 5
The in-order traversal in linked list form is:

1 - 2 - 3 - 4 - 5
Рекомендации по теме
Комментарии
Автор

Note: at the end the the l.next is returned as for some reason a 0 was getting appened at the beginning so to remove that i returning from 2 element in the list

algoranger
welcome to shbcf.ru