Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PRE=(L(n)è una lista corretta, P ha dimP elementi, chiamiamo vL(n)=L(n))
- nodo* match(nodo* &n, int*P, int dimP){
- if(!n )
- return 0;
- nodo * x = n;
- if(n->info == *P)
- if(tryM(n,P,dimP,n)){
- nodo * t = n;
- n = x;
- return t;
- }
- n->next = match(n->next,P,dimP);
- return n;
- }//match
- /*POST=(se in L(n) c’è un match di P, allora la funzione restituisce col return resto_mach(vL(n),P[0..dimP-1]) e L(n)=match(vL(n),P[0..dimP-1]),
- se invece non c’è il match allora la funzione restituisce vL(n)col return e n=0)*/
- //PRE=(L(n) e L(m) sono la stessa, corretta lista. P ha dimP elementi
- bool tryM(nodo *&n,int *P,int dimP, nodo* &m){
- if(!dimP){
- m = n;
- n = 0;
- return true;
- }//match completo
- if(n)
- if(*P == n->info)
- return tryM(n->next,P+1,dimP-1,m);
- else
- return false;
- }//tryM
- /*POST = Ritorna true sse esiste un match completo tra P e n, se esiste, restituisco in m la l(n) restante su cui è stato tolto match(n).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement