File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,6 +45,30 @@ def main():
4545 # Output: 1 2 3 4 5 6 7 8 9
4646
4747
48+ if __name__ == '__main__':
49+ main()
50+
51+ ```
52+
53+ ## ListNode
54+
55+ `basic_data_structure.nodes.list_node.ListNode`
56+
57+ If you'd like to create linked list by yourself, you can use `ListNode` class like so, for example:
58+
59+ ```python
60+ from basic_data_structure import ListNode
61+
62+
63+ def main():
64+ head = ListNode(1, ListNode(2, ListNode(3)))
65+ while head:
66+ print(head.value, end=' ')
67+ head = head.next
68+
69+ # Output: 1 2 3
70+
71+
4872if __name__ == '__main__':
4973 main()
5074
@@ -95,29 +119,7 @@ def main():
95119
96120 ```
97121
98- ## ListNode
99-
100- `basic_data_structure.nodes.list_node.ListNode`
101-
102- If you'd like to create linked list by yourself, you can use `ListNode` class like this, for example:
103-
104- ```python
105- from basic_data_structure import ListNode
106-
107-
108- def main():
109- head = ListNode(1, ListNode(2, ListNode(3)))
110- while head:
111- print(head.value, end=' ')
112- head = head.next
113-
114- # Output: 1 2 3
115-
116-
117- if __name__ == '__main__':
118- main()
119-
120- ```
122+ ## Public methods
121123"""
122124
123125from typing import Any , Optional
Original file line number Diff line number Diff line change @@ -37,20 +37,7 @@ def main() -> None:
3737
3838```
3939
40- ## Dunder methods
41-
42- 1. `__bool__` – return `False` if the stack is empty, `True` otherwise
43- ```python
44- while stack:
45- value = stack.pop()
46- ```
47- 2. `__len__` – return length (count of elements) of the stack
48- ```python
49- if len(stack) > 2:
50- ...
51- ```
52-
53- ### A note on iteration
40+ ## A note on iteration
5441
5542The `__iter__` and `__next__` methods are not implemented **intentionally**. If you want to iterate
5643over a Stack like this `for i in stack`, you're better off using built-in `list` instead, because
@@ -64,6 +51,21 @@ def main() -> None:
6451 element = stack.pop()
6552 ...
6653```
54+
55+ ## Dunder methods
56+
57+ 1. `__bool__` – return `False` if the stack is empty, `True` otherwise
58+ ```python
59+ while stack:
60+ value = stack.pop()
61+ ```
62+ 2. `__len__` – return length (count of elements) of the stack
63+ ```python
64+ if len(stack) > 2:
65+ ...
66+ ```
67+
68+ ## Public methods
6769"""
6870
6971from typing import Any
You can’t perform that action at this time.
0 commit comments