Advertisement
J00ker

Untitled

Jun 2nd, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. ///============================================
  8. ///                  greshit
  9. ///============================================
  10.  
  11.  
  12. struct Nod
  13. {
  14.     int info;
  15.     Nod *leg;
  16. };
  17.  
  18. Nod *L, *pare, *impare;
  19.  
  20. void Parcurgere(Nod *a)
  21. {
  22.     if(a == NULL)
  23.     {
  24.         cout << "Lista e vida consateanule!";
  25.         return;
  26.     }
  27.     for(Nod *p = a; p != NULL; p = p -> leg)
  28.         cout << p -> info << " ";
  29.     cout << "\n";
  30. }
  31.  
  32. int main()
  33. {
  34.     int i, x;
  35.     L = NULL; pare = NULL; impare = NULL;
  36.  
  37.     srand(time(0));
  38.     for(i = 1; i <= 25; i++)
  39.     {
  40.         x = rand() % 10 + 1;
  41.         Nod *p;
  42.         p = new Nod;
  43.         p -> info = x;
  44.         p -> leg = L;
  45.         L = p;
  46.     }
  47.  
  48.     Nod *p = L;
  49.     while(L != NULL)
  50.     {
  51.         Nod *q;
  52.         q = new Nod;
  53.         q = L;
  54.         if(L -> info % 2 == 0)
  55.         {
  56.             L = q -> leg;
  57.             q -> leg = pare;
  58.             pare = q;
  59.         }
  60.         else
  61.         {
  62.             L = q -> leg;
  63.             q -> leg = impare;
  64.             impare = q;
  65.         }
  66.     }
  67.  
  68.     cout << "L: "; Parcurgere(L);
  69.     //cout << "pare: "; Parcurgere(pare);
  70.     //cout << "impare: "; Parcurgere(impare);
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement