Skip to content

Commit 73c123f

Browse files
author
Vic-Nas
committed
Auto-generate docs and bump version to 0.3 [skip ci]
1 parent b40463b commit 73c123f

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2
1+
0.3

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="vicutils", # package name
5-
version="0.2",
5+
version="0.3",
66
packages=find_packages(), # finds vicutils folder automatically
77
install_requires=[], # optional, for dependencies
88
)

vicutils/printBin.html

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,62 @@ <h2 class="section-title" id="header-classes">Classes</h2>
329329
&#34;&#34;&#34;
330330
Represents a node in a binary tree.
331331

332+
Args:
333+
val: The value stored in the node, or a list to build a tree from.
334+
If a list is provided, builds tree level by level from left to right.
335+
Use None in the list for missing nodes.
336+
left: Reference to the left child node (only used when val is not a list)
337+
right: Reference to the right child node (only used when val is not a list)
338+
332339
Attributes:
333340
val: The value stored in the node
334341
left: Reference to the left child node
335342
right: Reference to the right child node
343+
344+
Example:
345+
&gt;&gt;&gt; # Create a single node
346+
&gt;&gt;&gt; node = BinaryNode(5)
347+
&gt;&gt;&gt;
348+
&gt;&gt;&gt; # Create a tree from a list
349+
&gt;&gt;&gt; root = BinaryNode([1, 2, 3, 4, 5, None, 7])
350+
&gt;&gt;&gt; # Creates:
351+
&gt;&gt;&gt; # 1
352+
&gt;&gt;&gt; # / \
353+
&gt;&gt;&gt; # 2 3
354+
&gt;&gt;&gt; # / \ \
355+
&gt;&gt;&gt; # 4 5 7
336356
&#34;&#34;&#34;
337357
def __init__(self, val=0, left=None, right=None):
338-
self.val = val
339-
self.left = left
340-
self.right = right
358+
# If val is a list, build tree from it
359+
if isinstance(val, list):
360+
if not val or val[0] is None:
361+
raise ValueError(&#34;Cannot create tree from empty list or list starting with None&#34;)
362+
363+
self.val = val[0]
364+
self.left = None
365+
self.right = None
366+
367+
queue = [self]
368+
i = 1
369+
370+
while queue and i &lt; len(val):
371+
node = queue.pop(0)
372+
373+
# Add left child
374+
if i &lt; len(val) and val[i] is not None:
375+
node.left = BinaryNode(val[i])
376+
queue.append(node.left)
377+
i += 1
378+
379+
# Add right child
380+
if i &lt; len(val) and val[i] is not None:
381+
node.right = BinaryNode(val[i])
382+
queue.append(node.right)
383+
i += 1
384+
else:
385+
self.val = val
386+
self.left = left
387+
self.right = right
341388

342389
def __str__(self):
343390
return str(self.val)
@@ -346,6 +393,17 @@ <h2 class="section-title" id="header-classes">Classes</h2>
346393
return str(self)</code></pre>
347394
</details>
348395
<div class="desc"><p>Represents a node in a binary tree.</p>
396+
<h2 id="args">Args</h2>
397+
<dl>
398+
<dt><strong><code>val</code></strong></dt>
399+
<dd>The value stored in the node, or a list to build a tree from.
400+
If a list is provided, builds tree level by level from left to right.
401+
Use None in the list for missing nodes.</dd>
402+
<dt><strong><code>left</code></strong></dt>
403+
<dd>Reference to the left child node (only used when val is not a list)</dd>
404+
<dt><strong><code>right</code></strong></dt>
405+
<dd>Reference to the right child node (only used when val is not a list)</dd>
406+
</dl>
349407
<h2 id="attributes">Attributes</h2>
350408
<dl>
351409
<dt><strong><code>val</code></strong></dt>
@@ -354,7 +412,18 @@ <h2 id="attributes">Attributes</h2>
354412
<dd>Reference to the left child node</dd>
355413
<dt><strong><code>right</code></strong></dt>
356414
<dd>Reference to the right child node</dd>
357-
</dl></div>
415+
</dl>
416+
<h2 id="example">Example</h2>
417+
<pre><code class="language-python-repl">&gt;&gt;&gt; # Create a single node
418+
&gt;&gt;&gt; node = BinaryNode(5)
419+
&gt;&gt;&gt;
420+
&gt;&gt;&gt; # Create a tree from a list
421+
&gt;&gt;&gt; root = BinaryNode([1, 2, 3, 4, 5, None, 7])
422+
&gt;&gt;&gt; # Creates:
423+
&gt;&gt;&gt; # 1
424+
&gt;&gt;&gt; # / &gt;&gt;&gt; # 2 3
425+
&gt;&gt;&gt; # / \ &gt;&gt;&gt; # 4 5 7
426+
</code></pre></div>
358427
</dd>
359428
</dl>
360429
</section>

0 commit comments

Comments
 (0)