...

codigo de colas Round robin

by yankees00000

on

Report

Category:

Documents

Download: 0

Comment: 0

1

views

Comments

Description

codigo para aplicacion RR
Download codigo de colas Round robin

Transcript

import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import javax.swing.JOptionPane; public class ExamenDeUnidad { private int tamArchivo() { int num = 0; try { File file = new File("./DeInfijaAPosfija/Texto"); FileReader fr; fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); while (br.ready()) { br.readLine(); num++; } br.close(); return num; } catch (IOException e) { return num; } } private String[] leer() throws FileNotFoundException, IOException { File file = new File("./DeInfijaAPosfija/Texto"); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String[] expresiones = new String[tamArchivo()]; int linea = 0; while (br.ready()) { expresiones[linea] = br.readLine(); linea++; } br.close(); return expresiones; } private static void escribir(String mensaje) throws IOException { File file = new File("./DeInfijaAPosfija/Resultados"); FileOutputStream fo = new FileOutputStream(file); PrintWriter pw = new PrintWriter(fo); pw.println(mensaje); pw.close(); } private static int prioridad(String signo) { if (signo.equals("(") || signo.equals(")") || signo.equals("[") || signo.equals("]")) return 0; if (signo.equals(">") || signo.equals(" "; for (int indice = 0; indice < partir.length; ind ice++) { if (partir[indice].equals("(")) pila.push(partir[indice]); else{ if (partir[indice].equals(")")) { while (!pila.getTop().equals("(" )) { salida += pila.p op(); } } else { if(prioridad(partir[indice]) != 4 ) { if(pila.isVacio() || prioridad(p artir[indice])> prioridad((String)pila.getTop())) pila.push(partir[indice] ); else { if(pila.getTop().equals( "(") || pila.getTop().equals("[")) pila.pop(); salida+=pila.getTop(); } } else salida+=partir[indice]; } } } while(!pila.isVacio()) { if(pila.getTop().equals("(") || pila.get Top().equals("[")) pila.pop(); salida+=pila.pop(); } } salidaFinal+=salida+" ---> " +evaluarExpresion(salida); salidaFinal+="\n"; ExamenDeUnidad.escribir(salidaFinal); } return salidaFinal; } private static String operacion(String c,String n,String nu2) { int num1=Integer.parseInt(nu2); int num2 = Integer.parseInt(n),res=0; String resultado=""; if(c.equals("+")) res= num1+num2; if(c.equals("-")) res = num1-num2; if(c.equals("*")) res = num1*num2; if(c.equals("/")) res = num1/num2; if(c.equals("%")) res= num1*num2; if(c.equals(">")) return num1 +" es menor a "+ num2; if(c.equals("
Fly UP