Guest User

Untitled

a guest
Jan 3rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. void inserisciXdopoY(plista p, int x, int y) {
  2. plista prec = p;
  3. plista corr = p->next;
  4. if (conta(prec,y)==0) { //inserisco il nodo x in coda
  5. while(corr->next) {
  6. prec = prec->next;
  7. corr = corr-> next;
  8. }
  9. corr = (plista) malloc(sizeof(lista));
  10. corr->info=x;
  11. prec=prec->next;
  12. prec->next=corr;
  13. corr->next=NULL;
  14. }
  15. else {
  16. while (corr->next) {
  17. if (prec->info==y) {
  18. corr = (plista) malloc(sizeof(lista));
  19. corr->info=x;
  20. corr->next = prec->next;
  21. prec->next = corr;
  22. prec=prec->next;
  23. corr=corr->next;
  24. }
  25. else {
  26. prec=prec->next;
  27. corr=corr->next;
  28. }
  29. }
  30. //Controllo dell'ultimo nodo
  31. if(corr->info==y) {
  32. corr = (plista) malloc(sizeof(lista));
  33. corr->info=x;
  34. prec=prec->next;
  35. prec->next=corr;
  36. corr->next=NULL;
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment