Home page |
![]() |
Teacher |
|
Online |
Il sito |
Competenze da acquisire |
Regole didattiche |
Contatore visite (dal 18-10-07) N° |
|
![]() |
||
|
|
|
|
|
|
|
|
||||||
data modifica: 10/06/18
Algoritmi Fondamentali
Le seguenti ricerche si utilizzano sui vettori e sui file; sono puramente indicative e si dovranno "configurare" per le applicazioni che le richiedono.Il linguaggio scelto è il VISUAL BASICSui file esistono 2 soluzioni possibili; ricorda che se hai bisogno di modificare il record allora devi usare la soluzione che utilizzi il numero di record Ricerca TotaleRicerca CompletaRicerca Completa con flagRicerca SequenzialeRicerca BinariaFusione di 2 vettori ordinati
Ricerca Totale Ricerca di Valore sul vettore V (o sul file #1 o sulla tabella TAB) |
|
su vettore |
su tabella |
valore = inputbox ("dammi il valore da cercare")for I = 1 to N if V(I)= Valore then msgbox V(i) end ifnext |
...(supponendo di utilizzare un textbox TxtDati)valore = inputbox ("dammi il valore da cercare")rsTabel.movefirstdo while not rsTabel.eof if rsTabel.campo = valore then riga = riga & rsTabel!campo1 & rstTabel!campo2 end if rsTabel.movenextloopTxtDati.text = riga |
su file |
|
valore = inputbox ("dammi il valore da cercare")for I = 1 to N GET #1,I,P if P.DATO = valore msgbox P.*****end if next |
valore = inputbox ("dammi il valore da cercare")do while not eof(1) GET #1,,P if P.DATO = valore msgbox P.*****end if loop |
Ricerca Completa Ricerca di Valore sul vettore V (o sul file #1) |
|
su vettore |
su tabella |
valore = inputbox ("dammi il valore da cercare")I = 1do while (I<=N) and (V(I)<>Valore) I= I+1loopIf I > N then msgbox "Il valore non è presente"else msgbox "Il valore non è presente"end if
|
...(supponendo di utilizzare un Textbox TxtDati)valore = inputbox ("dammi il dato da cercare")rsTabel.movefirstdo while not rsTabel.eof and rsTabel!DATO <> valore rsTabel.movenextloopIf rsTabel.eof then msgbox "Il valore non è presente" else riga = riga & rsTabel!campo1 & rstTabel!campo2 TxtDati.text = rigaend if |
su file |
|
valore = inputbox ("dammi il dato da cercare")I = 1 do while I<=N and P.DATO <> valore GET #1,I,P I = I +1 loop If I > N then msgbox "Il valore non è presente" else msgbox "Il valore è presente" end if |
valore = inputbox ("dammi il dato da cercare")do while not eof(1) and P.DATO <> valore () GET #1,,P loop If eof(1) the msgbox "Il valore non è presente" else msgbox "Il valore è presente" end if |
Ricerca Completa con Flag Ricerca di Valore sul vettore V (o sul file #1) di N elementi utilizzando il "flag" trovato |
|
su vettore |
su tabella |
valore = inputbox ("dammi il valore da cercare")trovato = falseI = 1do while (I<=N) and (not trovato) if (V(I)=valore) then trovato = true else I = I+1 end if loop if trovato then msgbox "Il valore è presente"else msgbox "Il valore non è presente"end if |
...(supponendo di utilizzare un Textbox TxtDati)valore = inputbox ("dammi il dato da cercare")trovato = false rsTabel.movefirstdo while not rsTabel.eof and not trovato If rsTabel.campo = valore then trovato = true end ifloopif trovato = true then riga = riga & rsTabel!campo1 & rstTabel!campo2 TxtDati.text = rigaelse msgbox "Il valore non è presente" end if |
su file |
|
valore = inputbox ("dammi il dato da cercare") trovato = false I = 1 do while I<=N and not trovato GET #1,I,P IF P.DATO = valore then trovato = true else I = I +1 endif loop if trovato then msgbox "Il valore è presente"else msgbox "Il valore non è presente"end if |
valore = inputbox ("dammi il dato da cercare")trovato = false do while not(eof(1)) and not trovato GET #1,,P IF P.DATO = valore then trovato = true endif loop if trovato then msgbox "Il valore è presente"else msgbox "Il valore non è presente"end if |
Ricerca Sequenziale Ricerca di Valore sul vettore V (o sul file #1) , ordinato, di N elementi |
|
su vettore |
su file |
valore = inputbox ("dammi il valore da cercare")I = 1 do while (I<=N) and (V(I)<Valore) I = I+1 loopIf I > N then msgbox "Il valore non è presente" elseif V(I)= valore then msgbox "Il valore è presente" else 'si è superato l'ordine logico msgbox "Il valore non è presente" end if |
valore = inputbox ("dammi il dato da cercare") GET #1,1,P I=1 do while I<=N and P.DATO < valore GET #1,I,P I = I +1 loop if I > N then msgbox "Il valore non è presente" elseif P.DATO = valore then msgbox "Il valore è presente " else 'si è superato l'ordine logico msgbox "Il valore non è presente" endif |
Ricerca binaria Ricerca di Valore sul vettore V ordinato, di N elementi |
|
valore = inputbox ("dammi il valore da cercare") I = 1 F= N do C = (I+F)\2 If Valore = V(C) then trovato = true elseif Valore > V[C] then I= C + 1 else F= C - 1 end if loop until trovato or (I > F) if trovato then msgbox ("Il valore è presente") else msgbox ("Il valore non è presente")end if |
|
Fusione ordinata di 2 vettori Sub FUSIONE (byval A as variant,byval B as variant, byref C as variant, byref P as byte); dim i as byte, J as byte, K as byte I=1 J=1 K=1 do while (I<=N) AND (J<=M) if A(I) < B(I) then C(K)=A(I) I=I+1 K=K+1 else C(K)=B(J) J=J+1 K=K+1end if loop do while I<=N C(K)=A(I) I=I+1 K=K+1 loop do while J<=M C(K)=B(J) J=J+1 K=K+1loop P=N+Mend sub |
|
Il TG diurno su e20 Sicilia, per il sito web dell'Ufficio Tributi, realizzato al Fermi
Il TG serale di e20 Sicilia, per il primo sito dell'Ufficio Tributi, realizzato al Fermi
Terra promessa
la mia partecipazione all'Eredità
Un professore da lanciare via a razzo!
Giornata da ..sballo