Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Do not answers silly

//
So I need to fill my stack with the characters of string and while i pop the characters 1 by 1 they will be added to another resultant string

*import java.util.*;
    public class ReverseStringUsingStack {
        private static String Reverse(String str) {
            int idx=0;
            Stack<Character> s = new Stack<Character>();
            while(idx< str.length()){
                s.push(str.charAt(idx));
            }

            StringBuilder result = new StringBuilder("");
            while(!s.isEmpty()){
                char curr = s.pop();
                result.append(curr);
            }
            return result.toString();
        }
        public static void main(String[] args) {
            String str = "abc";
            String ans = Reverse(str);
            System.out.println(ans);
        }
    }*

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You must increase idx.

    while (idx < str.length()) {
        s.push(str.charAt(idx));
        idx++;
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading