Java Stack Usage removeBackets(String cont)

Here you can find the source of removeBackets(String cont)

Description

remove Backets

License

Open Source License

Declaration

public static String removeBackets(String cont) 

Method Source Code

//package com.java2s;

import java.util.Stack;

public class Main {
    public static String removeBackets(String cont) {
        if (cont == null)
            return null;

        int len = cont.length();

        Stack<Character> stack = new Stack<Character>();

        char c;/*from  w  w  w .  j  av a  2  s. c  o m*/
        for (int i = 0; i < len; i++) {
            c = cont.charAt(i);
            if (c == ')') {
                while (true) {
                    c = (Character) stack.pop();
                    if (c == '(') {
                        break;
                    }
                }
            } else {
                stack.push(c);
            }
        }

        StringBuilder sb = new StringBuilder();

        while (stack.isEmpty() == false) {
            c = (Character) stack.pop();
            sb.append(c);
        }

        return sb.reverse().toString();
    }
}

Related

  1. getPostOrder(List inOrderList)
  2. getRelativePath(Stack pathStack)
  3. getSyllables(String pinyin)
  4. isDoubleQuote(Stack bufStack)
  5. normalizeAbsolutePath(String curDir)
  6. removeDotSegments(String relativePath)
  7. removeParenthesis(String text)
  8. resolveOneLineExpression(String line, String space, List target)
  9. resolveSeparateIfSentence(List lines, int cursor, List target, String space)