NeroReflex

Esercizio_1_11_5_2016

May 27th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. nodo* C(nodo*& Q, int k)
  2. {
  3.     if(!Q)
  4.         return NULL;
  5.     if(k==1)
  6.     {
  7.         nodo*a=Q;
  8.         Q=Q->next;
  9.         a->next=NULL;
  10.         return a;
  11.     }
  12.     else
  13.     {
  14.         nodo*b=C(Q->next,k-1);
  15.         nodo*a=Q;
  16.         Q=Q->next;
  17.         a->next=b;
  18.         return a;
  19.     }
  20. }
  21.  
  22. nodo* G(nodo*Q1, nodo*Q2,  int k)
  23. {
  24.    
  25.     if ((!Q1) && (!Q2)) return NULL;
  26.    
  27.     nodo *concat = C(Q1, k);
  28.    
  29.     nodo *temp = concat;
  30.     while (temp->next != NULL) temp = temp->next;
  31.     temp->next = C(Q2, k);
  32.    
  33.     while (temp->next != NULL) temp = temp->next;
  34.     temp->next = G(Q1, Q2, k);
  35.    
  36.     return concat;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment