Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. int isRipetuto(int value, nodo* Q){
  2.     if(Q){
  3.         if(Q->info == value) return 1 + isRipetuto(value, Q->next);
  4.         else return isRipetuto(value, Q->next);
  5.     }
  6.     else return -1;
  7. }
  8.  
  9. nodo* comprimiL(nodo* L){
  10.     if(L->next == NULL) return NULL;
  11.     else{
  12.         return new nodo(L->next->info, comprimiL(L->next));
  13.     }
  14. }
  15.  
  16. nodo* rimuoviTranneUltimaOccorrenza(nodo* &Q, int value, int c){
  17.     if(c==0) return NULL;
  18.     else if(Q){
  19.         if(Q->info == value){
  20.             Q=comprimiL(Q);
  21.             return new nodo(value, rimuoviTranneUltimaOccorrenza(Q, value, c-1));
  22.         }
  23.         else rimuoviTranneUltimaOccorrenza(Q->next, value, c);
  24.     }
  25. }
  26.  
  27. //ESERCIZIO 2 -- RICORSIVO
  28. FIFO tieni_ultimo_ric(nodo*&Q){
  29.     FIFO restanti;
  30.     if(!Q){
  31.         return restanti;
  32.     }
  33.     else{
  34.         int c = isRipetuto(Q->info, Q);
  35.         //cout<<Q->info<<": "<<c<<endl;
  36.         if(c>0){
  37.             nodo* T = rimuoviTranneUltimaOccorrenza(Q, Q->info, c);
  38.             //cout<<"!"<<endl;
  39.             //stampa_L(T);
  40.             return push_end(restanti, T);
  41.         }
  42.         restanti = tieni_ultimo_ric(Q->next);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement