Skip to content

Commit cf6eac1

Browse files
committed
Refactored ReverseStringUsingStack utility for reversing strings using stack
1 parent e03c7cd commit cf6eac1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/main/java/com/thealgorithms/strings/ReverseString.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ public static String reverse4(String str) {
7676
return str;
7777
}
7878
// Push each character of the string onto the stack
79-
for (char i : str.toCharArray()) {
80-
stack.push(i);
79+
for (char ch : str.toCharArray()) {
80+
stack.push(ch);
8181
}
8282
// Pop each character from the stack and append to the StringBuilder
8383
while (!stack.isEmpty()) {
8484
reversedString.append(stack.pop());
8585
}
8686
return reversedString.toString();
8787
}
88-
8988
}

0 commit comments

Comments
 (0)
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