Python
Python copied to clipboard
Stack using a fixed size array
Describe your change:
New implementation of the stack data structure
Checklist:
- [x] I have read CONTRIBUTING.md.
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Python files are placed inside an existing directory.
- [x] All filenames are in all lowercase characters with no spaces or dashes.
- [x] All functions and variable names follow Python naming conventions.
- [x] All function parameters and return values are annotated with Python type hints.
- [x] All functions have doctests that pass the automated testing.
- [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [ ] If this pull request resolves one or more open issues then the commit message contains
Fixes: #{$ISSUE_NO}.
https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/stack.py uses the Python list, I only use the Python list to simulate a fixed-sized array like the one in Java because Python doesn't have a built-in static array. It's a different implementation. I use the pointers to manage the list and resize it manually when it's full. Please have a look again, it's not a duplicate!! @poyea
@dylanbuchi But master/data_structures/stacks/stack.py:push contains technically your __resize, right? What I suggest is the two stack implementations use the same type - list - to simulate the operations.
@poyea Yes! I just don't use the built-in list methods or the resizing under the hood. So basically I'm simulating a static array using the list and the other one uses the list as-is: a dynamic array. I think it's helpful to also show this implementation.
What I was thinking is you may add this resize function to data_structures/stacks/stack.py because from my perspective these 2 implementations are similar. Then, you can also keep all the test cases.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.