The TransCompilator

Solved LeetCode program · 501 of 1,000

#0700 · Search in a Binary Search Tree

Easy Tree chunk-11.md

Original English source

The values is a list of 4, 2, 7, 1, and 3. The lefts is a list of 1, 3, -1, -1, and -1. The rights is a list of 2, 4, -1, -1, and -1. The wanted is 2. The node is 0.
Repeat while node is at least 0 and item node of values is not wanted.
If item node of values is more than wanted, set node to item node of lefts. If item node of values is less than wanted, set node to item node of rights.

The queue is an empty list of whole numbers. Place node into queue. The head is 0. The count is 1.
Repeat while head is less than count.
The current is item head of queue. Add 1 to head. Show item current of values. The left is item current of lefts. The right is item current of rights. If left is at least 0, Place left into queue, add 1 to count. If right is at least 0, Place right into queue, add 1 to count.

Open in Playground Browse all 1,000 problems

Expected stdout

2
1
3