|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1"> |
| 6 | +<meta name="generator" content="pdoc3 0.11.6"> |
| 7 | +<title>printBin API documentation</title> |
| 8 | +<meta name="description" content=""> |
| 9 | +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin> |
| 10 | +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin> |
| 11 | +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin> |
| 12 | +<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
| 13 | +<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style> |
| 14 | +<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
| 15 | +<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script> |
| 16 | +<script>window.addEventListener('DOMContentLoaded', () => { |
| 17 | +hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']}); |
| 18 | +hljs.highlightAll(); |
| 19 | +/* Collapse source docstrings */ |
| 20 | +setTimeout(() => { |
| 21 | +[...document.querySelectorAll('.hljs.language-python > .hljs-string')] |
| 22 | +.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3))) |
| 23 | +.forEach(el => { |
| 24 | +let d = document.createElement('details'); |
| 25 | +d.classList.add('hljs-string'); |
| 26 | +d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3); |
| 27 | +el.replaceWith(d); |
| 28 | +}); |
| 29 | +}, 100); |
| 30 | +})</script> |
| 31 | +</head> |
| 32 | +<body> |
| 33 | +<main> |
| 34 | +<article id="content"> |
| 35 | +<header> |
| 36 | +<h1 class="title">Module <code>printBin</code></h1> |
| 37 | +</header> |
| 38 | +<section id="section-intro"> |
| 39 | +</section> |
| 40 | +<section> |
| 41 | +</section> |
| 42 | +<section> |
| 43 | +</section> |
| 44 | +<section> |
| 45 | +<h2 class="section-title" id="header-functions">Functions</h2> |
| 46 | +<dl> |
| 47 | +<dt id="printBin.center"><code class="name flex"> |
| 48 | +<span>def <span class="ident">center</span></span>(<span>val, unitSize=None, fillChar=None)</span> |
| 49 | +</code></dt> |
| 50 | +<dd> |
| 51 | +<details class="source"> |
| 52 | +<summary> |
| 53 | +<span>Expand source code</span> |
| 54 | +</summary> |
| 55 | +<pre><code class="python">def center(val, unitSize=None, fillChar=None): |
| 56 | + """ |
| 57 | + Centers a value within a fixed width string. |
| 58 | + |
| 59 | + Args: |
| 60 | + val: The value to center |
| 61 | + unitSize: The total width of the output string (uses DEFAULT_UNIT_SIZE if None) |
| 62 | + fillChar: The character to use for padding (uses DEFAULT_FILL_CHAR if None) |
| 63 | + |
| 64 | + Returns: |
| 65 | + A centered string representation of val |
| 66 | + """ |
| 67 | + if unitSize is None: |
| 68 | + unitSize = DEFAULT_UNIT_SIZE |
| 69 | + if fillChar is None: |
| 70 | + fillChar = DEFAULT_FILL_CHAR |
| 71 | + return str(val).center(unitSize, fillChar)</code></pre> |
| 72 | +</details> |
| 73 | +<div class="desc"><p>Centers a value within a fixed width string.</p> |
| 74 | +<h2 id="args">Args</h2> |
| 75 | +<dl> |
| 76 | +<dt><strong><code>val</code></strong></dt> |
| 77 | +<dd>The value to center</dd> |
| 78 | +<dt><strong><code>unitSize</code></strong></dt> |
| 79 | +<dd>The total width of the output string (uses DEFAULT_UNIT_SIZE if None)</dd> |
| 80 | +<dt><strong><code>fillChar</code></strong></dt> |
| 81 | +<dd>The character to use for padding (uses DEFAULT_FILL_CHAR if None)</dd> |
| 82 | +</dl> |
| 83 | +<h2 id="returns">Returns</h2> |
| 84 | +<p>A centered string representation of val</p></div> |
| 85 | +</dd> |
| 86 | +<dt id="printBin.getDepth"><code class="name flex"> |
| 87 | +<span>def <span class="ident">getDepth</span></span>(<span>node: <a title="printBin.Node" href="#printBin.Node">Node</a>)</span> |
| 88 | +</code></dt> |
| 89 | +<dd> |
| 90 | +<details class="source"> |
| 91 | +<summary> |
| 92 | +<span>Expand source code</span> |
| 93 | +</summary> |
| 94 | +<pre><code class="python">def getDepth(node: Node): |
| 95 | + """ |
| 96 | + Calculates the depth (height) of a binary tree. |
| 97 | + |
| 98 | + Args: |
| 99 | + node: The root node of the tree |
| 100 | + |
| 101 | + Returns: |
| 102 | + The depth of the tree (number of levels from root to deepest leaf) |
| 103 | + """ |
| 104 | + if node == None: |
| 105 | + return 0 |
| 106 | + return 1 + max(getDepth(node.left), getDepth(node.right))</code></pre> |
| 107 | +</details> |
| 108 | +<div class="desc"><p>Calculates the depth (height) of a binary tree.</p> |
| 109 | +<h2 id="args">Args</h2> |
| 110 | +<dl> |
| 111 | +<dt><strong><code>node</code></strong></dt> |
| 112 | +<dd>The root node of the tree</dd> |
| 113 | +</dl> |
| 114 | +<h2 id="returns">Returns</h2> |
| 115 | +<p>The depth of the tree (number of levels from root to deepest leaf)</p></div> |
| 116 | +</dd> |
| 117 | +<dt id="printBin.nodeToMat"><code class="name flex"> |
| 118 | +<span>def <span class="ident">nodeToMat</span></span>(<span>node: <a title="printBin.Node" href="#printBin.Node">Node</a>,<br>depth=-1,<br>fillChar=None,<br>unitSize=None,<br>removeEmpty=True)</span> |
| 119 | +</code></dt> |
| 120 | +<dd> |
| 121 | +<details class="source"> |
| 122 | +<summary> |
| 123 | +<span>Expand source code</span> |
| 124 | +</summary> |
| 125 | +<pre><code class="python">def nodeToMat(node: Node, depth=-1, fillChar=None, unitSize=None, removeEmpty=True): |
| 126 | + """ |
| 127 | + Converts a binary tree into a 2D matrix representation for visualization. |
| 128 | + |
| 129 | + The matrix includes: |
| 130 | + - Even rows (0, 2, 4...): Node values |
| 131 | + - Odd rows (1, 3, 5...): Connection lines (/ and \\) |
| 132 | + |
| 133 | + Args: |
| 134 | + node: The root node of the tree to visualize |
| 135 | + depth: The depth of the tree (-1 for auto-calculation) |
| 136 | + fillChar: Character for padding (uses DEFAULT_FILL_CHAR if None) |
| 137 | + unitSize: Size for centering (uses DEFAULT_UNIT_SIZE if None) |
| 138 | + removeEmpty: Whether to remove empty leading columns |
| 139 | + |
| 140 | + Returns: |
| 141 | + A 2D list (matrix) representing the tree structure |
| 142 | + """ |
| 143 | + if unitSize is None: |
| 144 | + unitSize = DEFAULT_UNIT_SIZE |
| 145 | + if fillChar is None: |
| 146 | + fillChar = DEFAULT_FILL_CHAR |
| 147 | + |
| 148 | + if depth == -1: |
| 149 | + depth = getDepth(node) |
| 150 | + |
| 151 | + # Register all nodes with their binary path codes |
| 152 | + tree = register(node, fillChar=fillChar, unitSize=unitSize, code="", mem={}) |
| 153 | + |
| 154 | + # Create matrix: (2*depth - 1) rows x (2^depth - 1) columns |
| 155 | + mat = [[center("", unitSize=unitSize, fillChar=fillChar) for _ in range(2 ** depth - 1)] for _ in range(2 * depth - 1)] |
| 156 | + |
| 157 | + side = "left" |
| 158 | + leftBound, rightBound = 0, 2 ** depth - 2 |
| 159 | + |
| 160 | + # Start with all even column indices (where values can be placed) |
| 161 | + valueIndexes = [i for i in range(2 ** depth - 1) if i % 2 == 0] |
| 162 | + |
| 163 | + # Build matrix from bottom to top |
| 164 | + for level in range(2 * (depth - 1), -1, -1): |
| 165 | + # Odd levels: place connection characters (/ and \) |
| 166 | + if level % 2 != 0: |
| 167 | + for i, index in enumerate(valueIndexes): |
| 168 | + mat[level][index] = [center("/", unitSize=unitSize, fillChar=fillChar), center("\\", unitSize=unitSize, fillChar=fillChar)][i % 2] |
| 169 | + |
| 170 | + # Calculate parent positions (midpoints between child pairs) |
| 171 | + newIndexes = [] |
| 172 | + for i in range(0, len(valueIndexes) - 1, 2): |
| 173 | + newIndexes.append((valueIndexes[i] + valueIndexes[i + 1]) // 2) |
| 174 | + valueIndexes = newIndexes |
| 175 | + continue |
| 176 | + |
| 177 | + # Even levels: place node values |
| 178 | + # Generate all binary codes for current level |
| 179 | + codes = list(product(*["01" for _ in range(level // 2)])) |
| 180 | + codes = ["".join(code) for code in codes] |
| 181 | + |
| 182 | + for i, index in enumerate(valueIndexes): |
| 183 | + mat[level][index] = tree.get(codes[i], center("", unitSize=unitSize, fillChar=fillChar)) |
| 184 | + |
| 185 | + # Remove empty leading columns if requested |
| 186 | + if removeEmpty: |
| 187 | + for i in range(2 ** depth - 1): |
| 188 | + remove = False |
| 189 | + if all( |
| 190 | + mat[j][i] in [ |
| 191 | + center("", unitSize=unitSize, fillChar=fillChar), |
| 192 | + center("/", unitSize=unitSize, fillChar=fillChar), |
| 193 | + center("\\", unitSize=unitSize, fillChar=fillChar) |
| 194 | + ] for j in range(2 * depth - 1) |
| 195 | + ): |
| 196 | + remove = True |
| 197 | + if not remove: |
| 198 | + break |
| 199 | + for j in range(2 * depth - 1): |
| 200 | + mat[j][i] = "" |
| 201 | + |
| 202 | + return mat</code></pre> |
| 203 | +</details> |
| 204 | +<div class="desc"><p>Converts a binary tree into a 2D matrix representation for visualization.</p> |
| 205 | +<p>The matrix includes: |
| 206 | +- Even rows (0, 2, 4…): Node values |
| 207 | +- Odd rows (1, 3, 5…): Connection lines (/ and )</p> |
| 208 | +<h2 id="args">Args</h2> |
| 209 | +<dl> |
| 210 | +<dt><strong><code>node</code></strong></dt> |
| 211 | +<dd>The root node of the tree to visualize</dd> |
| 212 | +<dt><strong><code>depth</code></strong></dt> |
| 213 | +<dd>The depth of the tree (-1 for auto-calculation)</dd> |
| 214 | +<dt><strong><code>fillChar</code></strong></dt> |
| 215 | +<dd>Character for padding (uses DEFAULT_FILL_CHAR if None)</dd> |
| 216 | +<dt><strong><code>unitSize</code></strong></dt> |
| 217 | +<dd>Size for centering (uses DEFAULT_UNIT_SIZE if None)</dd> |
| 218 | +<dt><strong><code>removeEmpty</code></strong></dt> |
| 219 | +<dd>Whether to remove empty leading columns</dd> |
| 220 | +</dl> |
| 221 | +<h2 id="returns">Returns</h2> |
| 222 | +<p>A 2D list (matrix) representing the tree structure</p></div> |
| 223 | +</dd> |
| 224 | +<dt id="printBin.nodeToString"><code class="name flex"> |
| 225 | +<span>def <span class="ident">nodeToString</span></span>(<span>node: <a title="printBin.Node" href="#printBin.Node">Node</a>,<br>depth=-1,<br>fillChar=None,<br>unitSize=None,<br>removeEmpty=True)</span> |
| 226 | +</code></dt> |
| 227 | +<dd> |
| 228 | +<details class="source"> |
| 229 | +<summary> |
| 230 | +<span>Expand source code</span> |
| 231 | +</summary> |
| 232 | +<pre><code class="python">def nodeToString(node: Node, depth=-1, fillChar=None, unitSize=None, removeEmpty=True): |
| 233 | + """ |
| 234 | + Converts a binary tree into a string representation for visualization. |
| 235 | + |
| 236 | + Args: |
| 237 | + node: The root node of the tree to visualize |
| 238 | + depth: The depth of the tree (-1 for auto-calculation) |
| 239 | + fillChar: Character for padding (uses DEFAULT_FILL_CHAR if None) |
| 240 | + unitSize: Size for centering (uses DEFAULT_UNIT_SIZE if None) |
| 241 | + removeEmpty: Whether to remove empty leading columns |
| 242 | + |
| 243 | + Returns: |
| 244 | + A string representation of the tree with each row on a new line |
| 245 | + """ |
| 246 | + mat = nodeToMat(node, depth=depth, fillChar=fillChar, unitSize=unitSize, removeEmpty=removeEmpty) |
| 247 | + return "\n".join("".join(row) for row in mat)</code></pre> |
| 248 | +</details> |
| 249 | +<div class="desc"><p>Converts a binary tree into a string representation for visualization.</p> |
| 250 | +<h2 id="args">Args</h2> |
| 251 | +<dl> |
| 252 | +<dt><strong><code>node</code></strong></dt> |
| 253 | +<dd>The root node of the tree to visualize</dd> |
| 254 | +<dt><strong><code>depth</code></strong></dt> |
| 255 | +<dd>The depth of the tree (-1 for auto-calculation)</dd> |
| 256 | +<dt><strong><code>fillChar</code></strong></dt> |
| 257 | +<dd>Character for padding (uses DEFAULT_FILL_CHAR if None)</dd> |
| 258 | +<dt><strong><code>unitSize</code></strong></dt> |
| 259 | +<dd>Size for centering (uses DEFAULT_UNIT_SIZE if None)</dd> |
| 260 | +<dt><strong><code>removeEmpty</code></strong></dt> |
| 261 | +<dd>Whether to remove empty leading columns</dd> |
| 262 | +</dl> |
| 263 | +<h2 id="returns">Returns</h2> |
| 264 | +<p>A string representation of the tree with each row on a new line</p></div> |
| 265 | +</dd> |
| 266 | +<dt id="printBin.register"><code class="name flex"> |
| 267 | +<span>def <span class="ident">register</span></span>(<span>node: <a title="printBin.Node" href="#printBin.Node">Node</a>,<br>fillChar=None,<br>unitSize=None,<br>code='',<br>mem=None)</span> |
| 268 | +</code></dt> |
| 269 | +<dd> |
| 270 | +<details class="source"> |
| 271 | +<summary> |
| 272 | +<span>Expand source code</span> |
| 273 | +</summary> |
| 274 | +<pre><code class="python">def register(node: Node, fillChar=None, unitSize=None, code="", mem=None): |
| 275 | + """ |
| 276 | + Recursively registers all nodes in a tree with their binary path codes. |
| 277 | + |
| 278 | + Each node is assigned a binary code representing its position: |
| 279 | + - Empty string "" for root |
| 280 | + - "0" appended for left child |
| 281 | + - "1" appended for right child |
| 282 | + |
| 283 | + Args: |
| 284 | + node: The current node being processed |
| 285 | + fillChar: Character used for padding (uses DEFAULT_FILL_CHAR if None) |
| 286 | + unitSize: Size for centering values (uses DEFAULT_UNIT_SIZE if None) |
| 287 | + code: The binary path code for the current node |
| 288 | + mem: Dictionary mapping binary codes to centered node values |
| 289 | + """ |
| 290 | + if mem is None: |
| 291 | + mem = {} |
| 292 | + if node: |
| 293 | + mem[code] = center(node.val, unitSize=unitSize, fillChar=fillChar) |
| 294 | + register(node.left, fillChar=fillChar, unitSize=unitSize, code=code + "0", mem=mem) |
| 295 | + register(node.right, fillChar=fillChar, unitSize=unitSize, code=code + "1", mem=mem) |
| 296 | + return mem</code></pre> |
| 297 | +</details> |
| 298 | +<div class="desc"><p>Recursively registers all nodes in a tree with their binary path codes.</p> |
| 299 | +<p>Each node is assigned a binary code representing its position: |
| 300 | +- Empty string "" for root |
| 301 | +- "0" appended for left child |
| 302 | +- "1" appended for right child</p> |
| 303 | +<h2 id="args">Args</h2> |
| 304 | +<dl> |
| 305 | +<dt><strong><code>node</code></strong></dt> |
| 306 | +<dd>The current node being processed</dd> |
| 307 | +<dt><strong><code>fillChar</code></strong></dt> |
| 308 | +<dd>Character used for padding (uses DEFAULT_FILL_CHAR if None)</dd> |
| 309 | +<dt><strong><code>unitSize</code></strong></dt> |
| 310 | +<dd>Size for centering values (uses DEFAULT_UNIT_SIZE if None)</dd> |
| 311 | +<dt><strong><code>code</code></strong></dt> |
| 312 | +<dd>The binary path code for the current node</dd> |
| 313 | +<dt><strong><code>mem</code></strong></dt> |
| 314 | +<dd>Dictionary mapping binary codes to centered node values</dd> |
| 315 | +</dl></div> |
| 316 | +</dd> |
| 317 | +</dl> |
| 318 | +</section> |
| 319 | +<section> |
| 320 | +<h2 class="section-title" id="header-classes">Classes</h2> |
| 321 | +<dl> |
| 322 | +<dt id="printBin.Node"><code class="flex name class"> |
| 323 | +<span>class <span class="ident">Node</span></span> |
| 324 | +<span>(</span><span>val=0, left=None, right=None)</span> |
| 325 | +</code></dt> |
| 326 | +<dd> |
| 327 | +<details class="source"> |
| 328 | +<summary> |
| 329 | +<span>Expand source code</span> |
| 330 | +</summary> |
| 331 | +<pre><code class="python">class Node: |
| 332 | + """ |
| 333 | + Represents a node in a binary tree. |
| 334 | + |
| 335 | + Attributes: |
| 336 | + val: The value stored in the node |
| 337 | + left: Reference to the left child node |
| 338 | + right: Reference to the right child node |
| 339 | + """ |
| 340 | + def __init__(self, val=0, left=None, right=None): |
| 341 | + self.val = val |
| 342 | + self.left = left |
| 343 | + self.right = right |
| 344 | + |
| 345 | + def __str__(self): |
| 346 | + return str(self.val) |
| 347 | + |
| 348 | + def __repr__(self): |
| 349 | + return str(self)</code></pre> |
| 350 | +</details> |
| 351 | +<div class="desc"><p>Represents a node in a binary tree.</p> |
| 352 | +<h2 id="attributes">Attributes</h2> |
| 353 | +<dl> |
| 354 | +<dt><strong><code>val</code></strong></dt> |
| 355 | +<dd>The value stored in the node</dd> |
| 356 | +<dt><strong><code>left</code></strong></dt> |
| 357 | +<dd>Reference to the left child node</dd> |
| 358 | +<dt><strong><code>right</code></strong></dt> |
| 359 | +<dd>Reference to the right child node</dd> |
| 360 | +</dl></div> |
| 361 | +</dd> |
| 362 | +</dl> |
| 363 | +</section> |
| 364 | +</article> |
| 365 | +<nav id="sidebar"> |
| 366 | +<div class="toc"> |
| 367 | +<ul></ul> |
| 368 | +</div> |
| 369 | +<ul id="index"> |
| 370 | +<li><h3><a href="#header-functions">Functions</a></h3> |
| 371 | +<ul class=""> |
| 372 | +<li><code><a title="printBin.center" href="#printBin.center">center</a></code></li> |
| 373 | +<li><code><a title="printBin.getDepth" href="#printBin.getDepth">getDepth</a></code></li> |
| 374 | +<li><code><a title="printBin.nodeToMat" href="#printBin.nodeToMat">nodeToMat</a></code></li> |
| 375 | +<li><code><a title="printBin.nodeToString" href="#printBin.nodeToString">nodeToString</a></code></li> |
| 376 | +<li><code><a title="printBin.register" href="#printBin.register">register</a></code></li> |
| 377 | +</ul> |
| 378 | +</li> |
| 379 | +<li><h3><a href="#header-classes">Classes</a></h3> |
| 380 | +<ul> |
| 381 | +<li> |
| 382 | +<h4><code><a title="printBin.Node" href="#printBin.Node">Node</a></code></h4> |
| 383 | +</li> |
| 384 | +</ul> |
| 385 | +</li> |
| 386 | +</ul> |
| 387 | +</nav> |
| 388 | +</main> |
| 389 | +<footer id="footer"> |
| 390 | +<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.6</a>.</p> |
| 391 | +</footer> |
| 392 | +</body> |
| 393 | +</html> |
0 commit comments