List of utility methods to do Stack Usage
boolean | endsWithIgnoreWhiteSpace(String decl, String token) ends With Ignore White Space int index = decl.length() - 1; Stack<Character> stack = new Stack<Character>(); for (int i = 0; i < token.length(); index--) { if (decl.charAt(index) == ' ' || decl.charAt(index) == '\t') continue; char c = decl.charAt(index); stack.push(c); i++; ... |
Stack | getBinary(long input) get Binary Stack<Integer> binaryStack = new Stack<Integer>(); while (input != 0) { binaryStack.push((int) input % 2); input = input / 2; return binaryStack; |
String[] | getOperands(Stack get Operands String[] operands = new String[nOperands]; for (int j = nOperands - 1; j >= 0; j--) { if (stack.isEmpty()) { String msg = "Too few arguments supplied to operation. Expected (%d) operands but got (%d)!"; msg = String.format(msg, nOperands, nOperands - j - 1); throw new IllegalStateException(msg); operands[j] = stack.pop(); ... |
void | getPermutationsRec(List get Permutations Rec if (order[order.length - 1] != 0) { permutations.add(order.clone()); for (Stack<Byte> stack : remaining) { if (stack.empty()) { } else { order[index] = stack.pop(); getPermutationsRec(permutations, order, remaining, index + 1); ... |
List | getPostOrder(List get Post Order List<String> result = new ArrayList<>(); Stack<String> stack = new Stack<>(); for (int i = 0; i < inOrderList.size(); i++) { if (Character.isDigit(inOrderList.get(i).charAt(0))) { result.add(inOrderList.get(i)); } else { switch (inOrderList.get(i).charAt(0)) { case '(': ... |
String | getRelativePath(Stack get Relative Path StringBuilder sb = new StringBuilder(); sb.append('/'); int size = pathStack.size(); for (int i = 0; i < size; i++) { sb.append(pathStack.get(i)).append('/'); return sb.toString(); |
String[] | getSyllables(String pinyin) Breaks a pinyin string on tone markers List syllables = new ArrayList(); Stack last = new Stack(); Stack next = new Stack(); for (int i = pinyin.length() - 1; i >= 0; i--) { next.push(new Character(pinyin.charAt(i))); do { char c = ((Character) next.pop()).charValue(); ... |
boolean | isDoubleQuote(Stack Check whether the peek of the stack element is double quote. if (!bufStack.isEmpty() && bufStack.peek() == '"') { return true; return false; |
String | normalizeAbsolutePath(String curDir) Given an absolute path (starting with '/'), normalize it so that there are no ".." if (curDir == null) { return null; StringBuffer buf = new StringBuffer(curDir); int maxIndex = buf.length(); int thisIndex = buf.indexOf("/"); Stack<Integer> slashStack = new Stack<Integer>(); while ((thisIndex != -1) && (thisIndex != maxIndex)) { ... |
String | removeBackets(String cont) remove Backets if (cont == null) return null; int len = cont.length(); Stack<Character> stack = new Stack<Character>(); char c; for (int i = 0; i < len; i++) { c = cont.charAt(i); if (c == ')') { ... |