public void recoverTree(TreeNode root) { // Start typing your Java solution below // DO NOT write main() function first = null; second = null; // inOrder(root, null); Wrap w = new Wrap(); w.prev = null; inOrder(root, w); int tmp = first.val; first.val = second.val; second.val = tmp; }
private static Block generateGoFileBlock(ASTNode node, CommonCodeStyleSettings settings) { return new GoFileBlock( node, Alignment.createAlignment(), Indent.getAbsoluteNoneIndent(), Wrap.createWrap(WrapType.NONE, false), settings); }
private void inOrder(TreeNode curr, Wrap w) { if (curr == null) return; inOrder(curr.left, w); if (w.prev != null && w.prev.val > curr.val) { if (first == null) { first = w.prev; } second = curr; } w.prev = curr; inOrder(curr.right, w); }
public static Block generateBlock( ASTNode node, Indent indent, Alignment alignment, CommonCodeStyleSettings styleSettings) { PsiElement psi = node.getPsi(); if (psi instanceof GoBlockStatement) return new GoBlockStatementBlock(node, indent, styleSettings); if (psi instanceof GoFile) return generateGoFileBlock(node, styleSettings); if (psi instanceof GoPackageDeclaration) return generatePackageBlock(node, styleSettings); if (psi instanceof GoBinaryExpression) { return new GoBinaryExpressionBlock(node, alignment, NO_WRAP, styleSettings); } if (psi instanceof GoFunctionDeclaration) { return new GoFunctionDeclarationBlock(node, alignment, indent, styleSettings); } IElementType elementType = node.getElementType(); if (elementType == GoTokenTypes.pLPAREN) { return new GoLeafBlock(node, null, indent, NO_WRAP, styleSettings); } else if (elementType == GoTokenTypes.pRCURLY) { if (node.getTreeParent().getElementType() == GoElementTypes.LITERAL_COMPOSITE_VALUE) { boolean inFunctionCall = false; ASTNode nodeParent = node; while (nodeParent != null) { if (nodeParent.getElementType() == GoElementTypes.CALL_OR_CONVERSION_EXPRESSION) { int indentTabSize = styleSettings.getIndentOptions() == null ? 4 : styleSettings.getIndentOptions().INDENT_SIZE; return new GoLeafBlock( node, null, Indent.getSpaceIndent(indentTabSize * -1), NO_WRAP, styleSettings); } nodeParent = nodeParent.getTreeParent(); } } } else if (elementType == GoTokenTypes.kPACKAGE || elementType == GoTokenTypes.oSEMI) { return new GoLeafBlock( node, null, Indent.getAbsoluteNoneIndent(), Wrap.createWrap(WrapType.NONE, false), styleSettings); } else if (GoTokenTypeSets.COMMENTS.contains(elementType)) { return new GoLeafBlock( node, alignment, indent, Wrap.createWrap(WrapType.NONE, false), styleSettings); } else if (ALIGN_LIST_BLOCK_STATEMENTS.contains(elementType)) { return new GoAssignListBlock(node, alignment, indent, styleSettings); } else if (elementType == GoElementTypes.TYPE_STRUCT) { return new GoTypeStructBlock(node, alignment, indent, styleSettings); // } else if (elementType == GoElementTypes.TYPE_INTERFACE) { // return new GoTypeInterfaceBlock(node, alignment, indent, styleSettings); } else if (elementType == GoElementTypes.EXPRESSION_LIST) { return new GoExpressionListBlock(node, alignment, indent, styleSettings); } else if (elementType == GoElementTypes.UNARY_EXPRESSION) { return new GoUnaryExpressionBlock(node, alignment, indent, NO_WRAP, styleSettings); } else if (GoElementTypes.FUNCTION_CALL_SETS.contains(elementType)) { return new GoCallOrConvExpressionBlock(node, alignment, indent, NO_WRAP, styleSettings); } else if (elementType == GoElementTypes.PARENTHESISED_EXPRESSION) { return new GoParenthesisedExpressionBlock(node, alignment, indent, styleSettings); } else if (elementType == GoElementTypes.LABELED_STATEMENT) { return new GoLabeledStatmentBlock(node, styleSettings); } else if (elementType == GoElementTypes.FUNCTION_PARAMETER_LIST) { return new GoFunctionParameterListBlock(node, indent, styleSettings); } else if (elementType == GoElementTypes.FUNCTION_PARAMETER) { return new GoFunctionParameterBlock(node, indent, styleSettings); } return new GoBlock(node, alignment, indent, NO_WRAP, styleSettings); }
public static int test() { return wrapped.get(); }
@Override public void applyToTexture(final String option, final Texture texture) { Wrap.applyToTexture("Repeat", texture); }