About 2,230,000 results
Open links in new tab
  1. Reverse a String using Stack - GeeksforGeeks

    Apr 4, 2025 · Follow the steps given below to reverse a string using stack. Create an empty stack. One by one push all characters of string to stack. One by one pop all characters from stack and put them back to string. Time Complexity: O (n) Only one traversal to push and one to pop so O (n)+O (n) = O (n).

  2. Reverse an array using Stack - GeeksforGeeks

    Mar 25, 2025 · Follow the steps given below to reverse an array using stack. Create an empty stack. One by one push all elements of the array to stack. One by one pop all elements from the stack and push them back to the array.

  3. Java Program to Reverse a String using Stack - GeeksforGeeks

    Oct 21, 2020 · Convert character array to string. Return reversed string. Below is the implementation of the above approach. Time Complexity: O (n), where n is a number of characters in the stack. Auxiliary Space: O (n) for the stack.

  4. java - How do I reverse a String array? - Stack Overflow

    Nov 7, 2014 · To reverse the array you only have to iterate half of the array and start swapping the element from start with end. swap element (position from start) with element (end position - position from start) String temp = reverse[i];

  5. Reverse a string using a stack data structure | Techie Delight

    Dec 1, 2021 · This post will discuss how to reverse a string using the stack data structure in C/C++, Java, and Python using explicit stack and call stack.

  6. java - Reversing an array using a stack - Stack Overflow

    Reverse int array using stack. strArr[i] = String.valueOf(arr[i]); stack.push(strArr[i]); strArr[i] = stack.pop(); arr[i] = Integer.parseInt(strArr[i]); public static void main(String[]args){ Integer arr[] = {3,5,6,8}; Stack<Integer> st = new Stack<>(); for(int i =0;i<arr.length;i++){ st.push(arr[i]); for(int i =0;i<arr.length;i++){

  7. Java Program to Reverse a String Using Stack - Tpoint Tech

    Mar 17, 2025 · Approach to reverse a string using stack. Push the elements/characters of the string individually into the stack of datatype characters. Pop the elements/characters individually from the Stack until the stack becomes vacant. Add a popped component to the character array. Convert character array to string. Return turned around the string.

  8. Java Coding Challenge - Reverse a String using Stack - Java Guides

    In this blog post, we implemented a solution to reverse a string using a stack in Java. We walked through the logic step-by-step, explaining how the stack's LIFO principle helps reverse the order of characters.

  9. How do I reverse every string in a string array? - Stack Overflow

    May 19, 2020 · Simply iterate the array, and replace each entry with its reverse. You can use a StringBuilder to reverse a String, calling StringBuilder.reverse. Like, public static void reverse(String[] array) { for (int i = 0; i < array.length; i++) { array[i] = new StringBuilder(array[i]).reverse().toString(); } } And then to test it

  10. Reverse Elements of an Array Using Stack in Java - Online …

    System.out.println("Reversed array is ::"+Arrays.toString(reverseArray)); Learn how to reverse the elements of an array using a stack in Java with this step-by-step guide.

  11. Some results have been removed