Skip to content

feat: Add NearestElement stack algorithms and fix Javadoc build warnings#7434

Open
sabarirajan83 wants to merge 2 commits into
TheAlgorithms:masterfrom
sabarirajan83:nearest-elements-in-array
Open

feat: Add NearestElement stack algorithms and fix Javadoc build warnings#7434
sabarirajan83 wants to merge 2 commits into
TheAlgorithms:masterfrom
sabarirajan83:nearest-elements-in-array

Conversation

@sabarirajan83
Copy link
Copy Markdown

Description

This PR introduces NearestElement.java, which provides stack-based algorithms to efficiently find the nearest greater or smaller elements in an array (for both left and right directions).

  • Implements a Monotonic Stack approach to achieve O(n) time complexity.
  • Includes explicit safety checks (using short-circuit evaluation and ternary operators) to prevent EmptyStackException.
  • Includes comprehensive JUnit 5 tests in NearestElementTest.java.

Additionally, this PR fixes pre-existing documentation comment is not attached to any declaration errors in:

  • AnyBaseToAnyBase.java
  • InterpolationSearch.java
  • LinearSearch.java

These documentation changes ensure strict build compatibility with modern JDK versions (JDK 21+).

Fixes #7322

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Fixed 'documentation comment is not attached to any declaration' errors in:
- AnyBaseToAnyBase.java
- InterpolationSearch.java
- LinearSearch.java
These changes ensure build compatibility with modern JDK versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permutations in java

1 participant