Alguem tem idéias de coomo se faz o balanceamento, com pilha, em java?
[code]
public static void main(String[] args) throws IOException{
Stack<Character> pilha = new Stack<Character> ();
String text = "{([[]])}";
for(int i = 0; i <= text.length() - 1 /*TAMANNO*/ ; i++){
if(text.charAt(i) == '{' )
pilha.push('}');
else if('[' == text.charAt(i))
pilha.push(']');
else if('(' == text.charAt(i))
pilha.push(')');
}
System.out.println(text);
System.out.println(pilha.toString());
for(int i = 0; i <= text.length() - 1 /*TAMANNO*/ ; i++){
if(text.charAt(i) == '}' )
pilha.pop();
else if(']' == text.charAt(i))
pilha.pop();
else if(')' == text.charAt(i))
pilha.pop();
}
System.out.println(text);
if(pilha.isEmpty()!= true)
System.out.println("Verifique os simbolos ");
else System.out.println("balanceamento de simbolos correta");
}[/code]
Eu fiz esse exemplo, mai está muito básico, alguem manja de JFrame, nnão sei, ou alguem tem um exemplo de balanceamento de simbolos pra me repassar?
Eu gostaria de selecionar um arquivo talvez, e verificar se esta correto…
Valew