}else f.enfileirar(c);
}
//coloca todos os simbolos na fila pos fixada
while(!p.pilhaVazia()) {
f.enfileirar(p.desempilhar());
}
return f;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package projetoandreia;
import EstrurasDeDados.Pilha;
/**
*
* @author u14418
*/
public class EstaBalanceada {
public static boolean estaBalanceada(String E) throws Exception{
Pilha p = new Pilha(E.length());
for(int i=0; i<E.length(); i++){
if( E.charAt(i) == '('){
p.empilhar(i);
}
if( E.charAt(i) == ')'){
p.desempilhar();
}
}
return p.pilhaVazia();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package projetoandreia;
import EstrurasDeDados.Fila;
/**
*
* @author u14418
*/
public class ImprimePosFixa {
public static String imprimePosFixa (Fila f) throws Exception{
String expressao = "";
Fila aux = f.clonar();
char c;
while (!aux.filaVazia()){
c = (char)aux.consultaPrimeiro();
aux.desenfileirar();
expressao += (char)c;
}
return expressao;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package projetoandreia;
/*import EstrurasDeDados.*;
import static projetoandreia.ConvertePosFixa.convertePosFixa;
import static projetoandreia.EstaBalanceada.estaBalanceada;
import static projetoandreia.ImprimePosFixa.imprimePosFixa;
import static projetoandreia.ResultadoPilha.resultadoPilha;
import static projetoandreia.SalvaFilaNumerica.salvaFilaNumerica;
import static projetoandreia.TransformaEmLetra.transformaEmLetra;
*/
/**
*
* @author u14418
*/
public class ProjetoAndreia {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
/*
filaNumerica = salvaFilaNumerica(expressao);
System.out.println("TESTE " + filaNumerica);
aux =transformaEmLetra(expressao);
System.out.println("aux "+aux);
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package projetoandreia;
import EstrurasDeDados.*;
/**
*
* @author u14418
*/
public class ResultadoPilha {
public static String resultadoPilha (String e, Fila f, Fila num) throws Exc
eption {
Pilha p = new Pilha(e.length()*2);
int num1,num2;
int i=0;
char caracter;
String aux = "";
while(i < e.length()){
//verifica se simbolo
if(!f.filaVazia()){
caracter = (char)f.desenfileirar();
if ("ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(caracter)> -1){
p.empilhar(num.desenfileirar());
}else if (caracter=='+') {
num1 = p.desempilhar();
num2 = p.desempilhar();
p.empilhar(num1+num2);
}else if (caracter=='-'){
num1 = p.desempilhar();
num2 = p.desempilhar();
p.empilhar(num2-num1);
}else if (caracter=='*') {
num1 = p.desempilhar();
num2 = p.desempilhar();
p.empilhar(num1*num2);
}else if (caracter=='/'){
num1 = p.desempilhar();
num2 = p.desempilhar();
p.empilhar(num2/num1);
}
}
i++;
}
aux = p.toString();
return aux;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package projetoandreia;
import EstrurasDeDados.Fila;
/**
*
* @author u14418
*/
public class SalvaFilaNumerica {
public static Fila salvaFilaNumerica (String e) throws Exception{
Fila f_numerica = new Fila(e.length()*2);
String aux="";
int i=0;
String expressao = e.replaceAlla("[^\\d]", "+");
for (char c : expressao.toCharArray()){
if (c!='+'){
aux+=c;
}else
if (!aux.isEmpty()){
f_numerica.enfileirar(Integer.parseInt(aux));
aux="";
}
}
if (!aux.isEmpty())
f_numerica.enfileirar(Integer.parseInt(aux));
return f_numerica;
}
}
/*