Skip to content

[FEATURE REQUEST] Add Stack Implementation Using Linked List in Java #6715

@Ayush41

Description

@Ayush41

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting triageAwaiting triage from a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions