What would you like to share?
📝 Description
The current /stacks directory in the repository includes various stack algorithms and implementations (e.g., using two queues, min stacks, postfix/prefix evaluation, etc.), but it lacks an implementation of a Stack data structure using a Linked List.
I would like to contribute a clean, well-documented implementation of StackUsingLinkedList.java under the /stacks package.
💡 Proposed Solution
Implement a StackUsingLinkedList class that supports the following standard stack operations:
push(T data) – insert an element onto the stack
pop() – remove and return the top element
peek() – view the top element without removing it
isEmpty() – check if the stack is empty
size() – return the number of elements in the stack
Implementation Details
- Use a singly linked list (with a
Node inner class) to store elements.
- Ensure O(1) time complexity for push and pop operations.
- Follow the repository’s naming conventions and JavaDocs style comments.
- Include a small
main method or test snippet demonstrating the functionality.
Additional information
No response
What would you like to share?
📝 Description
The current
/stacksdirectory in the repository includes various stack algorithms and implementations (e.g., using two queues, min stacks, postfix/prefix evaluation, etc.), but it lacks an implementation of a Stack data structure using a Linked List.I would like to contribute a clean, well-documented implementation of
StackUsingLinkedList.javaunder the/stackspackage.💡 Proposed Solution
Implement a
StackUsingLinkedListclass that supports the following standard stack operations:push(T data)– insert an element onto the stackpop()– remove and return the top elementpeek()– view the top element without removing itisEmpty()– check if the stack is emptysize()– return the number of elements in the stackImplementation Details
Nodeinner class) to store elements.mainmethod or test snippet demonstrating the functionality.Additional information
No response