Python icon indicating copy to clipboard operation
Python copied to clipboard

Stack using a fixed size array

Open dylanbuchi opened this issue 4 years ago • 5 comments
trafficstars

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}.

dylanbuchi avatar Oct 20 '21 20:10 dylanbuchi

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 avatar Oct 22 '21 09:10 dylanbuchi

@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 avatar Oct 22 '21 10:10 poyea

@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.

dylanbuchi avatar Oct 22 '21 11:10 dylanbuchi

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.

poyea avatar Oct 26 '21 11:10 poyea

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.

stale[bot] avatar Apr 28 '22 16:04 stale[bot]