About 12,500 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 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.

  3. Reverse a String – Complete Tutorial - GeeksforGeeks

    Jan 29, 2025 · # Python program to reverse a string using stack def reverseString (s): stack = [] # Push the characters into stack for char in s: stack. append (char) # Prepare a list to hold the reversed characters rev = [''] * len (s) # Pop the characters from stack into the reversed list for i in range (len (s)): rev [i] = stack. pop # Join the list to ...

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

    Oct 21, 2020 · Push the character one by one into the Stack of datatype character. Pop the character one by one from the Stack until the stack becomes empty. Add a popped element to the character array. Convert character array to string. Return reversed string. Below is the implementation of the above approach.

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

    In this blog post, we will discuss how to reverse a string using a stack in Java. We will walk through the implementation using a utility class Stacks, along with code snippets to illustrate each step. You are given a string, and your task is to reverse it using a stack.

  6. Reverse a String using Stack Data Structure - Java Guides

    In this article, we will discuss how to reverse a string using stack operations. This program uses stack operations to reverse a word (string). First, we push each character to the stack, then we will pop each char from the stack. public String reverseWord (String word) { StringBuilder stringBuilder = new StringBuilder ();

  7. Reverse a String using Stack in Java - Techie Delight

    Apr 1, 2024 · This post will discuss how to reverse a string using Stack in Java. The following example demonstrates how to reverse a string with a Stack data structure in Java. Following are the complete steps: Create an empty stack of characters. Convert given string into character array using String.toCharArray() method and push each character of it into ...

  8. Reverse a String using a Stack | Stacks | PrepBytes Blog

    Sep 26, 2022 · The idea is to traverse the given string from left to right and push each character in the stack. Then, pop the characters from the stack one by one and append them to a new string. The newly created will be the reverse of the input string because of the LIFO (Last-in-first-out) property of the stack data structure.

  9. Reverse a string using stack - Includehelp.com

    Dec 19, 2017 · Code explanation to reverse a string using stack. The Below Code has three parts, a Push function, a Pop function and the main function. The Push function checks whether the stack is full or not. If the stack is full it’s not do anything but if not it takes input from the user and push it to the top of the stack.

  10. Reverse a String Using Stack in Java - Master Coding

    In this post, we will use Java to reverse a string with the aid of a stack. 2. Program Steps. 1. Create a Stack class with operations: push (), pop (), and isEmpty (). 2. Push each character of the input string onto the stack. 3. Pop characters from the stack and construct the reversed string. 4. Display the reversed string. 3. Code Program.

Refresh