|
2 | 2 |
|
3 | 3 | ## How this Exercise is Structured in Python
|
4 | 4 |
|
5 |
| -While `stacks` and `queues` can be implemented using `lists`, `collections.deque`, `queue.LifoQueue`, and `multiprocessing.Queue`, this exercise expects a ["Last in, First Out" (`LIFO`) stack][Baeldung: The Stack Data Structure] (_interactive example [here][LIFO Stack]_) using a _custom-made_ [singly linked list][singly linked list]. |
| 5 | +While `stacks` and `queues` can be implemented using `lists`, `collections.deque`, `queue.LifoQueue`, and `multiprocessing.Queue`, this exercise expects a ["Last in, First Out" (`LIFO`) stack][baeldung: the stack data structure] using a _custom-made_ [singly linked list][singly linked list]: |
| 6 | + |
| 7 | +<br> |
6 | 8 |
|
7 | 9 | 
|
8 | 10 |
|
9 |
| -This should not be confused with a [`LIFO` stack using a dynamic array or list][LIFO Stack Array], which may use a `list` underneath. |
| 11 | +<br> |
| 12 | + |
| 13 | +This should not be confused with a [`LIFO` stack using a dynamic array or list][lifo stack array], which may use a `list`, `queue`, or `array` underneath. |
10 | 14 | Dynamic array based `stacks` have a different `head` position and different time complexity (Big-O) and memory footprint.
|
11 | 15 |
|
| 16 | +<br> |
| 17 | + |
12 | 18 | 
|
13 | 19 |
|
14 |
| -See these two Stack Overflow questions for some considerations: [Array-Based vs List-Based Stacks and Queues][Stack Overflow: Array-Based vs List-Based Stacks and Queues] and [Differences between Array Stack, Linked Stack, and Stack][Stack Overflow: What is the difference between Array Stack, Linked Stack, and Stack]. |
| 20 | +<br> |
15 | 21 |
|
| 22 | +See these two Stack Overflow questions for some considerations: [Array-Based vs List-Based Stacks and Queues][stack overflow: array-based vs list-based stacks and queues] and [Differences between Array Stack, Linked Stack, and Stack][stack overflow: what is the difference between array stack, linked stack, and stack]. |
16 | 23 | For more details on linked lists, `LIFO` stacks, and other abstract data types (`ADT`) in Python:
|
17 | 24 |
|
| 25 | +- [Baeldung: Linked-list Data Structures][baeldung linked lists] (_covers multiple implementations_) |
| 26 | +- [Geeks for Geeks: Stack with Linked List][geeks for geeks stack with linked list] |
| 27 | +- [Mosh on Abstract Data Structures][mosh data structures in python] (_covers many `ADT`s, not just linked lists_) |
18 | 28 |
|
19 |
| -- [Real Python: Linked Lists][Real Python Linked Lists] (_covers multiple implementations_) |
20 |
| -- [Towards Data Science: Demystifying the Linked List][towards data science demystifying the linked list] |
21 |
| -- [Towards Data Science: Singly Linked Lists][singly linked list] |
22 |
| -- [Geeks for Geeks: Stack with Linked List][Geeks for Geeks Stack with Linked List] |
23 |
| -- [Scaler Topics: Stacks in Python][Scaler Topics Stack in Python] |
24 |
| -- [Mosh on Abstract Data Structures][Mosh Data Structures in Python] (_covers many `ADT`s, not just linked lists_) |
| 29 | +<br> |
25 | 30 |
|
| 31 | +## Classes in Python |
26 | 32 |
|
27 | 33 | The "canonical" implementation of a linked list in Python usually requires one or more `classes`.
|
28 |
| -For a good introduction to `classes`, see the [Class section of the Official Python Tutorial][classes tutorial]. |
29 |
| - |
| 34 | +For a good introduction to `classes`, see the [concept:python/classes]() and companion exercise [exercise:python/ellens-alien-game](), or [Class section of the Official Python Tutorial][classes tutorial]. |
30 | 35 |
|
31 | 36 | <br>
|
32 | 37 |
|
33 | 38 | ## Special Methods in Python
|
34 | 39 |
|
35 |
| -The tests for this exercise will also be calling `len()` on your `LinkedList`. |
| 40 | +The tests for this exercise will be calling `len()` on your `LinkedList`. |
36 | 41 | In order for `len()` to work, you will need to create a `__len__` special method.
|
37 |
| -For details on implementing special or "dunder" methods in Python, see [Python Docs: Basic Object Customization][basic customization] and [Python Docs: object.__len__(self)][__len__]. |
| 42 | +For details on implementing special or "dunder" methods in Python, see [Python Docs: Basic Object Customization][basic customization] and [Python Docs: object.**len**(self)][__len__]. |
38 | 43 |
|
39 | 44 | <br>
|
40 | 45 |
|
41 | 46 | ## Building an Iterator
|
42 | 47 |
|
43 | 48 | To support looping through or reversing your `LinkedList`, you will need to implement the `__iter__` special method.
|
44 |
| -See [implementing an iterator for a class.](https://docs.python.org/3/tutorial/classes.html#iterators) for implementation details. |
| 49 | +See [implementing an iterator for a class.][custom iterators] for implementation details. |
45 | 50 |
|
46 | 51 | <br>
|
47 | 52 |
|
@@ -72,28 +77,25 @@ class EmptyListException(Exception):
|
72 | 77 | """
|
73 | 78 | def __init__(self, message):
|
74 | 79 | self.message = message
|
75 |
| - |
| 80 | + |
76 | 81 | # raising an EmptyListException
|
77 | 82 | raise EmptyListException("The list is empty.")
|
78 | 83 | ```
|
79 | 84 |
|
80 |
| - |
81 |
| -[Baeldung: The Stack Data Structure]: https://www.baeldung.com/cs/stack-data-structure |
82 |
| -[Geeks for Geeks Stack with Linked List]: https://www.geeksforgeeks.org/implement-a-stack-using-singly-linked-list/ |
83 |
| -[LIFO Stack Array]: https://courses.cs.washington.edu/courses/cse373/16wi/Hashing/visualization/StackArray.html |
84 |
| -[LIFO Stack]: https://courses.cs.washington.edu/courses/cse373/16wi/Hashing/visualization/StackLL.html |
85 |
| -[Mosh Data Structures in Python]: https://programmingwithmosh.com/data-structures/data-structures-in-python-stacks-queues-linked-lists-trees/ |
86 |
| -[Real Python Linked Lists]: https://realpython.com/linked-lists-python/ |
87 |
| -[Scaler Topics Stack in Python]: https://www.scaler.com/topics/stack-in-python/ |
88 |
| -[Stack Overflow: Array-Based vs List-Based Stacks and Queues]: https://stackoverflow.com/questions/7477181/array-based-vs-list-based-stacks-and-queues?rq=1 |
89 |
| -[Stack Overflow: What is the difference between Array Stack, Linked Stack, and Stack]: https://stackoverflow.com/questions/22995753/what-is-the-difference-between-array-stack-linked-stack-and-stack |
90 | 85 | [__len__]: https://docs.python.org/3/reference/datamodel.html#object.__len__
|
| 86 | +[baeldung linked lists]: https://www.baeldung.com/cs/linked-list-data-structure |
| 87 | +[baeldung: the stack data structure]: https://www.baeldung.com/cs/stack-data-structure |
91 | 88 | [basic customization]: https://docs.python.org/3/reference/datamodel.html#basic-customization
|
92 | 89 | [built-in errors]: https://docs.python.org/3/library/exceptions.html#base-classes
|
93 | 90 | [classes tutorial]: https://docs.python.org/3/tutorial/classes.html#tut-classes
|
| 91 | +[custom iterators]: https://docs.python.org/3/tutorial/classes.html#iterators |
94 | 92 | [customize errors]: https://docs.python.org/3/tutorial/errors.html#user-defined-exceptions
|
95 | 93 | [exception base class]: https://docs.python.org/3/library/exceptions.html#Exception
|
| 94 | +[geeks for geeks stack with linked list]: https://www.geeksforgeeks.org/implement-a-stack-using-singly-linked-list/ |
| 95 | +[lifo stack array]: https://www.scaler.com/topics/stack-in-python/ |
| 96 | +[mosh data structures in python]: https://programmingwithmosh.com/data-structures/data-structures-in-python-stacks-queues-linked-lists-trees/ |
96 | 97 | [raise statement]: https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement
|
97 | 98 | [raising exceptions]: https://docs.python.org/3/tutorial/errors.html#raising-exceptions
|
98 |
| -[singly linked list]: https://towardsdatascience.com/python-linked-lists-c3622205da81 |
99 |
| -[towards data science demystifying the linked list]: https://towardsdatascience.com/demystifying-linked-list-258dfb9f2176 |
| 99 | +[singly linked list]: https://blog.boot.dev/computer-science/building-a-linked-list-in-python-with-examples/ |
| 100 | +[stack overflow: array-based vs list-based stacks and queues]: https://stackoverflow.com/questions/7477181/array-based-vs-list-based-stacks-and-queues?rq=1 |
| 101 | +[stack overflow: what is the difference between array stack, linked stack, and stack]: https://stackoverflow.com/questions/22995753/what-is-the-difference-between-array-stack-linked-stack-and-stack |
0 commit comments