Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- ///============================================
- /// greshit
- ///============================================
- struct Nod
- {
- int info;
- Nod *leg;
- };
- Nod *L, *pare, *impare;
- void Parcurgere(Nod *a)
- {
- if(a == NULL)
- {
- cout << "Lista e vida consateanule!";
- return;
- }
- for(Nod *p = a; p != NULL; p = p -> leg)
- cout << p -> info << " ";
- cout << "\n";
- }
- int main()
- {
- int i, x;
- L = NULL; pare = NULL; impare = NULL;
- srand(time(0));
- for(i = 1; i <= 25; i++)
- {
- x = rand() % 10 + 1;
- Nod *p;
- p = new Nod;
- p -> info = x;
- p -> leg = L;
- L = p;
- }
- Nod *p = L;
- while(L != NULL)
- {
- Nod *q;
- q = new Nod;
- q = L;
- if(L -> info % 2 == 0)
- {
- L = q -> leg;
- q -> leg = pare;
- pare = q;
- }
- else
- {
- L = q -> leg;
- q -> leg = impare;
- impare = q;
- }
- }
- cout << "L: "; Parcurgere(L);
- //cout << "pare: "; Parcurgere(pare);
- //cout << "impare: "; Parcurgere(impare);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement