Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. struct nod{int info;
  5. nod *urm;};
  6. nod *prim, *ultim;
  7. void creare_adaugare(nod *&prim, nod*& ultim)
  8. {
  9. nod *q=new nod;
  10. q->urm=NULL;
  11. cin>>q->info;
  12. if(prim==NULL)
  13. {
  14. prim=q;
  15. ultim=q;
  16. }
  17. else
  18. {
  19. ultim->urm=q;
  20. ultim=q;
  21. }
  22. }
  23. void listare()
  24. {
  25. nod *c;
  26. c=prim;
  27. while(c!=0)
  28. {
  29. cout<<c->info<<" ";
  30. c=c->urm;
  31. }
  32. cout<<endl;
  33. }
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39. int i,n,k=0;
  40. cin>>n;
  41. for(i=0;i<n;i++)
  42. creare_adaugare(prim,ultim);
  43. nod *c,*a;
  44. c=prim;
  45.  
  46. while(c!=NULL)
  47. {
  48. if(c->info%2==1)
  49. {k++;
  50. break;}
  51. c=c->urm;
  52. }
  53. if(k==1)
  54. {a=new nod;
  55. a->info=4;
  56. a->urm=c->urm;
  57. c->urm=a;
  58. if(c==ultim)
  59. ultim=a;
  60. listare();}
  61. else cout<<"nu exista";
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement