Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int isRipetuto(int value, nodo* Q){
- if(Q){
- if(Q->info == value) return 1 + isRipetuto(value, Q->next);
- else return isRipetuto(value, Q->next);
- }
- else return -1;
- }
- nodo* comprimiL(nodo* L){
- if(L->next == NULL) return NULL;
- else{
- return new nodo(L->next->info, comprimiL(L->next));
- }
- }
- nodo* rimuoviTranneUltimaOccorrenza(nodo* &Q, int value, int c){
- if(c==0) return NULL;
- else if(Q){
- if(Q->info == value){
- Q=comprimiL(Q);
- return new nodo(value, rimuoviTranneUltimaOccorrenza(Q, value, c-1));
- }
- else rimuoviTranneUltimaOccorrenza(Q->next, value, c);
- }
- }
- //ESERCIZIO 2 -- RICORSIVO
- FIFO tieni_ultimo_ric(nodo*&Q){
- FIFO restanti;
- if(!Q){
- return restanti;
- }
- else{
- int c = isRipetuto(Q->info, Q);
- //cout<<Q->info<<": "<<c<<endl;
- if(c>0){
- nodo* T = rimuoviTranneUltimaOccorrenza(Q, Q->info, c);
- //cout<<"!"<<endl;
- //stampa_L(T);
- return push_end(restanti, T);
- }
- restanti = tieni_ultimo_ric(Q->next);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement