Home page

Teacher

On

line

Il sito

Competenze da acquisire

Regole didattiche

Contatore visite
 (dal 18-10-07)
Hit Counter
  Esercitazion PON / TIC Album Fotografico ricreazione_e_video Forum didattico Progetti Alunni Corsi per docenti Download    

IIS: Ragioneria

1°Anno  CAT

2°Anno AFM

3° Anno AFM

3° Anno  SIA

4°Anno AFM

4°Anno SIA

5°Anno SIA


Algoritmi fondamentali


Flow Chart


Codice


Ricordi

Statistiche

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 BASIC
Sui 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 Totale
Ricerca Completa
Ricerca Completa con flag
Ricerca Sequenziale
Ricerca Binaria
Fusione 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 if
next
...(supponendo di utilizzare un textbox TxtDati)
valore = inputbox ("dammi il valore da cercare")
rsTabel.movefirst
do while not rsTabel.eof 
        if rsTabel.campo = valore then
               riga = riga & rsTabel!campo1 & rstTabel!campo2
        end if  
        rsTabel.movenext
loop
TxtDati.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 = 1
do while (I<=N) and (V(I)<>Valore) 
        I= I+1
loop
If 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.movefirst
do while not rsTabel.eof and rsTabel!DATO <> valore
        rsTabel.movenext
loop
If rsTabel.eof then               
        msgbox "Il valore non è presente"  
else                       
        riga = riga & rsTabel!campo1 & rstTabel!campo2
        TxtDati.text = riga
end 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 = false
I = 1
do 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.movefirst
do while not rsTabel.eof and not trovato
        If rsTabel.campo = valore then 
               trovato = true 
        end if
loop
if trovato = true then 
        riga = riga & rsTabel!campo1 & rstTabel!campo2
        TxtDati.text = riga
else
        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               
loop
If 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+1
          end 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+1
     loop
     P=N+M
end sub