vuoi
o PayPal
tutte le volte che vuoi
Testo formattato
ADD MEDSTORE VMEDLOAD@ VMEDSUB XJNZ AVANTIWRITE MEDHALTAVANTI:JGZ ELSELOAD MEDADD# 1STORE INFJUMP FINEIFELSE: LOAD MEDSUB# 1STORE SUPFINEIF:JUMP WHILEFINEWHILE:WRITE# -1HALTEsercizio 4.Albero binario di ricerca inziale: (visita anticipata con un albero vuoto denotatoda ‘.’)17 -4 -5 . . -2 -3 . . 14 -1 . 12 . . . 20 19 . . 25 . .Dopo rimozione di -4 l’albero diventa:17 -3 -5 . . -2 . 14 -1 . 12 . . . 20 19 . . 25 . .Heap iniziale: (contenuto array)[-5,-4,14,-1,-3,20,19,17,25,12,-2]Dopo estrazione del minimo (-5):[-4,-3,14,-1,-2,20,19,17,25,12]Esercizio 5.Una soluzione (prototipo) direttamente basata sulle classi del collection framework di Java è suggerita di seguito.package poo.appello240114;public class Connessione {//classe di oggetti immutabiliprivate String origine, destinazione, percorso;private int lunghezza;public String getOrigine(){ return origine; }public String getDestinazione(){ return destinazione; }public String getPercorso(){ return percorso;
}public int getLunghezza(){ return lunghezza; }
public Connessione( String origine, String destinazione, String percorso, int lunghezza ){this.origine=origine; this.destinazione=destinazione; this.percorso=percorso;this.lunghezza=lunghezza;}
public String toString(){return "<<<"+origine+","+destinazione+">,"+percorso+">,"+lunghezza+">";}
//toStringpublic boolean equals( Object o ){if( !(o instanceof Connessione) ) return false;if( o==this ) return true;Connessione c=(Connessione)o;return this.origine.equals(c.origine)&&this.destinazione.equals(c.destinazione);}
//equalspublic int hashCode(){final int MULT=43;int h=origine.hashCode();h=h*MULT+destinazione.hashCode();h=h*MULT+lunghezza;return h;}
//hashCode}//Connessionepackage poo.appello240114;import java.util.*;import java.io.*;public class Programma {static String NOME="[a-zA-Z][a-zA-Z0-9]*";static String NUMERO="[1-9][0-9]+";
TRIPLA=NOME+""[\\s]+"+NOME+""[\\s]+"+NOME; static String QUADRUPLA=TRIPLA+""[\\s]+"+NUMERO; memorizza(private static void Map<String,LinkedList<Connessione>> rete, String nomeFile ) throwsIOException{ BufferedReader br=new BufferedReader( new FileReader(nomeFile) ); String linea=null; for(;;){ linea=br.readLine(); if( linea==null ) break; if( !linea.matches(QUADRUPLA) ){ br.close(); throw new RuntimeException(""File "+nomeFile+" malformato"); } Scanner sl=new Scanner(linea); sl.useDelimiter(""[\\s]+""); String org=sl.next(); String dst=sl.next(); String pat=sl.next(); int lung=Integer.parseInt( sl.next() ); Connessione nuova=new Connessione(org,dst,pat,lung); if( rete.containsKey(org) ){ LinkedList<Connessione> ll=rete.get(org); for( Connessione cs: ll ){ if( cs.getPercorso().equals(nuova.getPercorso() )){ sl.close(); br.close(); throw new RuntimeException(""Rete malformata"); } } } }