Advertisement
akanoce

DoubleReturn_LinkedList

May 11th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. //PRE=(L(n)è una lista corretta, P ha dimP elementi, chiamiamo vL(n)=L(n))
  2. nodo* match(nodo* &n, int*P, int dimP){
  3.    
  4.     if(!n )
  5.         return 0;
  6.    
  7.     nodo * x = n;
  8.    
  9.     if(n->info == *P)
  10.         if(tryM(n,P,dimP,n)){
  11.             nodo * t = n;
  12.            
  13.             n = x;
  14.             return t;
  15.            
  16.         }
  17.        
  18.         n->next =  match(n->next,P,dimP);
  19.         return n;
  20.    
  21. }//match
  22. /*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]),
  23. se invece non c’è il match allora la funzione restituisce vL(n)col return e n=0)*/
  24.  
  25. //PRE=(L(n) e L(m) sono la stessa, corretta lista. P ha dimP elementi
  26. bool tryM(nodo *&n,int *P,int dimP, nodo* &m){
  27.    
  28.     if(!dimP){
  29.         m = n;
  30.         n = 0;
  31.         return true;
  32.     }//match completo
  33.    
  34.    
  35.     if(n)
  36.         if(*P == n->info)
  37.             return tryM(n->next,P+1,dimP-1,m);
  38.         else
  39.             return false;
  40.    
  41.    
  42.    
  43. }//tryM
  44. /*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