Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. struct nod{int info;nod*leg;};
  5. nod*vf;
  6. void creare(nod*&vf)
  7. { nod*p;
  8.   int n,i;
  9.   vf=new nod;
  10.   vf->leg=NULL;
  11.   cout<<"dati prima valoare";
  12.   cin>>vf->info;
  13.   cout<<"dati numarul de noduri";
  14.   cin>>n;
  15.   for(i=2;i<=n;i++)
  16.   { p=new nod;
  17.     cout<<"dati valoarea";
  18.     cin>>p->info;
  19.     p->leg=vf;
  20.     vf=p;
  21.   }
  22. }
  23. void afisare(nod*vf)
  24. {   nod*p;
  25. p=vf;
  26. while(p!=NULL)
  27.     {   cout<<p->info<<"  ";
  28.         p=p->leg;}
  29.  
  30. }
  31. void stergerevalk(nod*&vf, int k)
  32. {   nod *q, *r, *p;
  33.  
  34. while(vf->info==k)      
  35.     {nod*p=vf;
  36.     p=p->leg;                   ///stergem nodurile cu val k daca sunt consecutive la inceputul listei
  37.     delete vf;
  38.     vf=p;
  39.     }
  40.  
  41. p=vf;
  42.  
  43. while(p->leg->leg!=NULL)
  44. {   if(p->leg->info==k)
  45.         {   q=p->leg;          
  46.             r=q->leg;           ///stergem nodurile cu val k din interiorul listei
  47.             p->leg=r;
  48.             delete q;
  49.         }
  50.     p=p->leg;
  51. }
  52. }
  53.  
  54.  
  55. int main()
  56.     {
  57.  
  58. creare (vf);
  59. afisare(vf);
  60. cout<<endl;
  61.  
  62. stergerevalk(vf,5);
  63. afisare(vf);
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement