ePerTutti


Appunti, Tesina di, appunto informatica

PILA



ricerca 1
ricerca 2

PILA

Dichiarazione


Type elemento= string[1]

Punta=^tipopila;

tipopila=record

dato:elemento;

p:punta;

end

tpila=class

cima:punta;



function pilavuota:boolean;

constructor creapila;

procedure inserisci(ele:elemento);

procedure estrai(var ele:elemento;var err:boolean);

end;


implementazione


constructor tpila.creapila;

begin

cima:=nil;

end;

function tpila.pilavuota:boolean;

begin

if cima=nil then

pilavuota:=true

else

pilavuota:=false;

end if

end


procedure tpila.inserisci(ele:elemento)

var p1:punta;

begin

new(p1);

p1^.dato:=ele;

if pilavuota then

begin

cima:=p1;

p1^.punt :=nil ;

end

else

begin

p1^.p :=cima;

cima:=p1;

end

endif

end


procedure tpila.estrai(var ele:elemento;var err:boolean)

var p1:punta;

begin

if pilavuota then

err:=true;

else

err:=false;

p1=cima;

ele=cima^.dato;

cima=cima^.punt;

dispose(p1);

end;

end;


CODA

DICHIARAZIONE


Type elemento=string[1];

punta=^tipocoda;

tipocoda=record

dato:elemento;

punt:punta;

end;

tcoda=class

cima,fondo:punta;

constructor creacoda;

function codavuota:boolean;

procedure inserisci(ele:elemento);

procedure vedicima(var ele:elemento;var err:boolean);

procedure scoda(var err:boolean);

end type;


implementation


constructor tcoda.creacoda;

begin

cima:=nil;

fondo:=nil;

end;


function tcoda.codavuota:boolean;

begin

if cima=fondo then

codavuota:=true

else

codavuota:=false;

end if

end


procedure tcoda.inserisci(ele:elemento);

var p1:punta;

begin

new(p1);

p1^.dato=ele;

p1^.punt=nil;

if codavuota then

cima=p1;

fondo=p1;

else

fondo^.punt=p1;

fondo=p1;

end if

end


procedure tcoda.vedicima(var ele:elemento;var err:boolean);

begin

if codavuota then

err:=true

else

err:=false;

ele=cima^.dato;

end if

end


procedure tcoda.elimina(var err:boolean)

var p1:punta;

begin

if codavuota then

err:=true

else

err:=false;

p1=cima;

cima:=cima^.punt;

dispose(p1);

end if

end


LISTA


DICHIARAZIONE

Type ele=string[1];

punta=^tipolista;

tipolista=record

dato:ele;

punt:punta;

end;

tlista=class

lista:punta;

constructor crealista;

function listavuota:boolean;

procedure inserisci(ele:elemento);

procedure elimina(var trovato:boolean;var err:boolean;ele:elemento)

procedure cerca stampa(ele:elemento;var err:boolean)

end;


IMPLEMENTAZIONE


constructor tlista.crealista

begin

Lista=nil;

end;


funtion tlista.listavuota:boolean;

begin

if lista=nil then

listavuota=true

else listavuota=false

end



Procedure tlista.inserisci(ele:elemento);

var p1,prec,succ:punta;



begin

new(p1);

p1^.dato=ele

if listavuota then

begin

p1^.punt=nil

lista=p1

end

else

if ele<lista^.dato then

p1^.punt=lista

lista=p1

else

prec=lista

succ=lista^.punt

while (succ<>nil)and (ele<succ^.dato) then

begin

prec=suc

succ=succ^.punt

end

p1^.punt=succ

prec^.punt=p1

end

end


procedure tlista.elimina(var trovato,err:boolean; ele:elemento)

var prec,succ,app:punta

begin

if listavuota then

err=true

else

err=false

app=lista

if lista^.dato=ele then

app=lista

lista=lista^.punt

dispose(app)

else

begin

prec=lista

succ=lista^.punt

trovato=false

while (succ^.dato<>ele)and(suc^.punt<>nil) do

begin

prec=succ

succ=suc^.punt

if succ^.dato=ele then trovato=true

end

if trovato=true then

prec^.p=succ^.p

dispose(succ)

end

end

end




ALBERO


Type elemento=<Ele>

punta = ^nodo

nodo=record

dato:ele

ps:punta

pd:punta

end

albero =class

radice:punta

constructor creaalbero

function alberovuoto:boolean

procedure visita-pre(rad:punta)

procedure visita-sim(rad:punta)

procedure visita-post(rad:punta)

procedure inserisci(rad:punta;ele:elemento)

end


implementation


constructor creaalbero;

begin

radice=nil;

end


procedure visita-pre(rad:punta)

begin

if alberovuoto then

write(rad^.dato)

visita-pre(rad^.ps)

visita-pre(rad^.pd)

end if

end


procedure visita-post(rad:punta)

begin

if alberovuoto then

write(rad^.dato)

visita-post(rad^.ps)

visita-post(rad^.pd)

end if

end


procedure visita-sim(rad:punta)

begin

if alberovuoto then

visita-sim(rad^.ps)

write(rad^.dato)

visita-sim(rad^.pd)

end if

end


procedure inserisci(var rad:punta;ele:elemento);

var p,j,i:punta;

begin

new(p)

p^.dato=ele

p^.ps=nil

p^.pd=nil

if alberovuoto then

radice=p

else

i=radice

while i<>nil do

j=i

if i^.dato<ele then

i=i^.pd

else

i=i^.ps

end if

end while

if j^.dato<ele then

j^.pd=p

else

j^.ps=p

end if

end if

end































Privacy

© ePerTutti.com : tutti i diritti riservati
:::::
Condizioni Generali - Invia - Contatta