Solved LeetCode program · 465 of 1,000
#0655 · Print Binary Tree
Original English source
Keep a shared values holding 1, 2, 3, and 4. Keep a shared lefts holding 1, -1, -1, and -1. Keep a shared rights holding 2, 3, -1, and -1. Keep a shared depths as an empty list of whole numbers. Keep a shared places as an empty list of whole numbers. Keep a shared height of 0. Keep a shared tall of 0. Keep a shared foundnode of 0. Keep a shared celltext as empty text.
To measure from node (a whole number) with depth (a whole number). If node is less than 0, return. If depth is more than height, set height to depth. Measure from item node of lefts with depth plus 1. Measure from item node of rights with depth plus 1.
To mark from node (a whole number) with level (a whole number) and place (a whole number). If node is less than 0, return. Set item node of depths to level. Set item node of places to place. The steps is tall minus 2 minus level. The gap is shift 1 left by steps. The leftplace is place minus gap. The rightplace is place plus gap. Mark from item node of lefts with level plus 1 and leftplace. Mark from item node of rights with level plus 1 and rightplace.
To find at row (a whole number) with column (a whole number). The pick is -1.
For every node from 0 to the last position of values.
If item node of depths is row and item node of places is column, set pick to node. Set foundnode to pick.
To describe from node (a whole number). The piece is format whole number item node of values as text. Set celltext to piece.
Measure from 0 with 1. Set tall to height. The wide is 1. The steps is 0.
Repeat while steps is less than tall.
Set wide to wide times 2. Add 1 to steps.
Decrease wide by 1. The middle is wide minus 1. Set middle to middle divided by 2. The gap is wide plus 1. Set gap to gap divided by 4.
For every node from 0 to 3.
Place 0 into depths. Place 0 into places.
Mark from 0 with 0 and middle. The line is empty text. Place "[" into line.
For every row from 0 to tall minus 1.
If row is more than 0, Place "," into line. Place "[" into line.
For every column from 0 to wide minus 1.
If column is more than 0, Place "," into line. Place "\"" into line. Find at row with column. The celltext is empty text. If foundnode is at least 0, describe from foundnode. Place celltext into line. Place "\"" into line. If column is wide minus 1, Place "]" into line.
Place "]" into line. Show line.
Expected stdout
[["","","","1","","",""],["","2","","","","3",""],["","","4","","","",""]]