-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use slice appending instead of insertion at zeroth index in "stack array" implementation #543
Comments
Feel free to open a pull request fixing this issue. |
Hello, |
Yes, it is open. |
hey assign me this issue under hacktoberfest |
Issues will not be assigned to a single individual. If anyone wishes to work on any issue just open a pull request and we will review it. |
Can the code style tests that failed be resolved by running gofmt -s -w stackarray.go ? |
Yes it can. |
Description
Current stack array implementation stores the last inserted value at zeroth index of the backing slice. This is inefficient as each push operation will require a new allocation and copying of contents in the current slice.
Inserting latest element to the last index (append) will also help in reusing existing slices's remaining capacity when multiple push and pop operations happens in mixed order.
Also, the current implementation uses a global variable as the backing slice. It should be implemented as an object and global mutable variables should be avoided.
The text was updated successfully, but these errors were encountered: