ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Infijo A Postfijo


Enviado por   •  10 de Noviembre de 2013  •  707 Palabras (3 Páginas)  •  246 Visitas

Página 1 de 3

import java.util.Scanner;

import java.util.Stack;

public class Notaciones {

public static void main(String[] args) {

System.out.println("*Escriba una notacion Infija: ");

Scanner leer = new Scanner(System.in);

//Depurar

String expr = depurar(leer.nextLine());

String[] arrayInfix = expr.split(" ");

//Declaración de las pilas

Stack < String > E = new Stack < String > (); //Pila entrada

Stack < String > O = new Stack < String > (); //Pila temporal para operadores

Stack < String > S = new Stack < String > (); //Pila salida

//Añadir la array a la Pila de entrada (E)

for (int i = arrayInfix.length - 1; i >= 0; i--) {

E.push(arrayInfix[i]);

}

try {

//Algoritmo Infijo a Postfijo

while (!E.isEmpty()) {

switch (pref(E.peek())){

case 1:

O.push(E.pop());

break;

case 3:

case 4:

while(pref(O.peek()) >= pref(E.peek())) {

S.push(O.pop());

}

O.push(E.pop());

break;

case 2:

while(!O.peek().equals("(")) {

S.push(O.pop());

}

O.pop();

E.pop();

break;

default:

S.push(E.pop());

}

}

...

Descargar como (para miembros actualizados)  txt (2.6 Kb)  
Leer 2 páginas más »
Disponible sólo en Clubensayos.com