https://github.com/dubisdev/pointer-stack-structure
A JavaScript implementation of a stack with a pointer
https://github.com/dubisdev/pointer-stack-structure
data-structures pointers stack
Last synced: about 1 year ago
JSON representation
A JavaScript implementation of a stack with a pointer
- Host: GitHub
- URL: https://github.com/dubisdev/pointer-stack-structure
- Owner: dubisdev
- License: mit
- Created: 2023-02-01T19:07:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-01T21:10:58.000Z (about 3 years ago)
- Last Synced: 2025-01-24T06:48:21.224Z (about 1 year ago)
- Topics: data-structures, pointers, stack
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@dubisdev/pointer-stack-structure
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# @dubisdev/pointer-stack-structure
This package implements something similar to a stack, but with a pointer. This is useful when you want to keep a stack of items, but you also want to navigate through the stack.
Use cases:
- Keep track of commands in a terminal (like in a shell)
- A chat history
- List of visited pages in a browser
- Anywhere you want to store a list of items and navigate through them sequentially
## Principles
- The data structure is a simple array of items (type can be defined by the user)
- New items are added at the end of the array.
- The last added item can be accessed using the `peek` method.
- When a new item is added, the pointer is set to that item (the last).
- Navigation is done using a pointer that points to the current item. Youcan use `peek` anytime to get the last item without moving the pointer.
- You can navigate through the history using the `getPrevious` and `getNext` methods or
- Set the pointer to a specific item using the `setPointer` method.
## License
MIT © [David Jiménez](https://dubis.dev)