The TransCompilator

Solved LeetCode program · 502 of 1,000

#0701 · Insert into a Binary Search Tree

Medium Tree chunk-11.md

Original English source

The key is 5. Keep a shared values holding 4, 2, 7, 1, 3, and key. Keep a shared lefts holding 1, 3, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, -1, -1, -1, and -1. Keep a shared newspot of the last position of values.

To attach from node (a whole number) with key (a whole number). If key is less than item node of values, Step left from node with key, return. Step later from node with key.

To step left from node (a whole number) with key (a whole number). The left is item node of lefts. If left is less than 0, set item node of lefts to newspot, return. Attach from left with key.

To step later from node (a whole number) with key (a whole number). The later is item node of rights. If later is less than 0, set item node of rights to newspot, return. Attach from later with key.

Attach from 0 with key. The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. Show item node of values. The left is item node of lefts. The right is item node 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

4
2
7
1
3
5