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