Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct nodo{int info; nodo* next; nodo(int a =0, nodo* b=0){info=a; next=b;}};
- struct nodoL{nodo* info; nodoL* next; nodoL(nodo* a =0, nodoL* b=0){info=a; next=b;}};
- nodo* clone(nodo*L)
- {
- if(L)
- return new nodo(L->info,clone(L->next));
- return 0;
- }
- void stampaL(nodo*L)
- {
- if(L)
- {cout<<L->info<<' '; stampaL(L->next);}
- else
- cout<<endl;
- }
- void stampaLL(nodoL*LL,int n)
- {
- if(LL)
- {cout<<"fetta "<<n<<") "; stampaL(LL->info); stampaLL(LL->next,n+1);}
- }
- nodo* faiL(int n)
- {
- if(n>0)
- return new nodo(n, faiL(n-1));
- return 0;
- }
- int contaNodi(nodo*L){
- if(!L) return 0;
- return 1+contaNodi(L->next);
- }
- nodo* split(nodo*&L, int x){
- if(!L) return 0;
- if(x==0) {nodo* tmp=0; return tmp;}
- if(x>contaNodi(L)) return 0; //se il numero di nodi da prelevare รจ maggiore del numero di nodi presenti L resta invariato
- nodo* tmp=L;
- L=L->next;
- tmp->next=split(L, x-1);
- return tmp;
- }
- nodoL* affettaric(nodo*&L, int*A, int dimA){
- if(!L) return 0;
- // if(!A) return 0;
- if(!dimA) return 0;
- nodoL* tmp=new nodoL;
- nodo* o=split(L, A[0]);
- tmp->info=o;
- tmp->next=affettaric(L, A+1, dimA-1);
- return tmp;
- }
- main()
- {
- cout<<"start"<<endl;
- nodo* L=faiL(10);
- nodo*L0=clone(L);
- int n, A[10];
- cin >> n;
- for(int i=0; i<n; i++)
- cin >> A[i];
- nodoL*K=affettaric(L,A,n);
- cout<<"Lric=";
- stampaL(L);
- cout<<"LLric:"<<endl;
- stampaLL(K,1);
- cout<<endl;
- /* K=affettaiter(L0,A,n);
- cout<<"Liter=";
- stampaL(L0);
- cout<<"LLiter:"<<endl;
- stampaLL(K,1);*/
- cout<<"end"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement