-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
* @param str string to be reversed using stack | ||
* @return reversed string | ||
*/ | ||
public static String reverse(String str) { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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));
}
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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
clang-format -i --style=file path/to/your/file.java