Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. struct nod
  8. {
  9. int info;
  10. nod * urm;
  11. };
  12. void sterge(nod * & p);
  13. void ad_inc (nod * & p, int x);
  14. void afisare(nod* p);
  15. int main()
  16. {
  17. nod *prim = NULL;
  18. int nr, n;
  19. cin>>n;
  20. for(int i;i<=n;i++)
  21. {
  22. cin>>nr;
  23. ad_inc(prim,nr);
  24. }
  25. afisare(prim);
  26.  
  27. return 0;
  28. }
  29.  
  30. void adaugare(nod * & p, int x)
  31. {
  32. nod* nou =new nod;
  33. nou -> info =x;
  34. nou -> urm =NULL;
  35. if(p==NULL)
  36. {
  37. p=nou;
  38. }
  39. else
  40. {
  41. nod*ultim=p;
  42. while(ultim->urm!=NULL)
  43. ultim = ultim->urm;
  44. ultim -> urm=nou;
  45. }
  46. }
  47.  
  48. void afisare(nod* p)
  49. {
  50. while (p)
  51. {
  52. cout<<p->info<<" ";
  53. p=p-> urm;
  54. }
  55. cout<< endl;
  56. }
  57.  
  58. void ad_inc (nod * & p , int x)
  59. {
  60. if(!p)
  61. {
  62. p= new nod;
  63. p->info = x;
  64. p-> urm =NULL;
  65. }
  66. else
  67. {
  68. nod *nou;
  69. nou=new nod;
  70. nou->info=x;
  71. nou->urm=p;
  72. p=nou;
  73. }
  74.  
  75.  
  76. }
  77. void sterge(nod * & p)
  78. {
  79. nod * q;
  80. while(p !=NULL && p->info%2 == 0)
  81. {
  82. nod* g=p;
  83. p=p->urm;
  84. delete q;
  85. }
  86. nod * d=p;
  87. while(d!=NULL)
  88. if(d->urm->info%2==0)//de va sterge d->urm
  89. {
  90. nod*q= d->urm;
  91. d->urm=q->urm;
  92. delete q;
  93. }
  94. else
  95. d=d->urm;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement