Advertisement
a53

FLsiDublu

a53
May 25th, 2022
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. int FLsiDublu(Nod *head)
  2. {
  3. int n=0;
  4. Nod *p=head;
  5. while(p!=NULL)
  6. ++n,p=p->leg;
  7. if(n%2)
  8. return -1;
  9. else
  10. {
  11. p=head;
  12. int m=n/2;
  13. Nod *q;
  14. while(m)
  15. {
  16. --m;
  17. if(m==0)
  18. q=p;
  19. p=p->leg;
  20. }
  21. int val=q->info;
  22. q=q->leg;
  23. m=n/2;
  24. bool ok=false;
  25. p=head;
  26. while(m--)
  27. {
  28. if(p->info!=q->info)
  29. {
  30. ok=true;
  31. break;
  32. }
  33. p=p->leg,q=q->leg;
  34. }
  35. if(ok)
  36. return -1;
  37. else
  38. return val;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement