Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. void inserare(nod * & p) {
  2.     if (p->urm == NULL && p->info % 2 == 0) { // verific daca lista are un singur element si daca acesta esta par
  3.         nod* tmp = new nod;
  4.         tmp->info = p->info * 2;
  5.         tmp->urm = p;
  6.         p = tmp;
  7.     } else {
  8.         nod *it = p;
  9.         while (it->urm != NULL) {
  10.             if(it->urm->info % 2 == 0) {
  11.                 nod *tmp = new nod;
  12.                 tmp->info = it->urm->info * 2;
  13.                 tmp->urm = it->urm;
  14.                 it->urm = tmp;
  15.                 it = tmp->urm; // ma pozitionez pe elementul par inaintea caruia am creeat dublul sau
  16.                
  17.             } else {
  18.                 it = it->urm;
  19.             }
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement