Skip to content

Add ReverseStringUsingStack utility for reversing strings using stack #6450

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

navaneedan07
Copy link

@navaneedan07 navaneedan07 commented Jul 29, 2025

  • 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 code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Jul 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.05%. Comparing base (24f4090) to head (379cb67).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6450      +/-   ##
============================================
+ Coverage     75.04%   75.05%   +0.01%     
- Complexity     5534     5539       +5     
============================================
  Files           685      686       +1     
  Lines         19208    19217       +9     
  Branches       3706     3709       +3     
============================================
+ Hits          14414    14424      +10     
  Misses         4239     4239              
+ Partials        555      554       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

* @param str string to be reversed using stack
* @return reversed string
*/
public static String reverse(String str) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be better to have next check here. And update javadoc that method throw such exception.

    if (str == null) {
        throw new IllegalArgumentException("Input string cannot be null");
    }

}

@Test
void testNullInput() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And remove this test and add this:

@Test
void testNullInput() {
    assertThrows(IllegalArgumentException.class, () -> ReverseStringUsingStack.reverse(null));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also suggest moving the method inside the existing ReverseString file, so that all different approaches are in one class to keep the previous approach.

return str;
}
// Push each character of the string onto the stack
for (char i : str.toCharArray()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name i in the for-each loop might be misleading, i would rename it to ch

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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy