Advertisement
nicuvlad76

Untitled

Nov 13th, 2023
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. /**
  4.  Liste liniare simplu inlantuite=LLSI
  5.  
  6.  1. Adaugare la Final =AddLast
  7. */
  8. struct nod
  9. {
  10.   int info;
  11.   nod *urm;
  12. };
  13. nod *p;
  14.  
  15. void adaugare(nod * & p , int x)
  16. {
  17.   ///adaugare nod la final
  18.   nod* q=new nod;
  19.   q->info=x;
  20.   q->urm=NULL;
  21.  
  22.   if(p==0)///lista vida
  23.     p=q;
  24.   else
  25.   {
  26.       nod* u;
  27.       for(u=p; u->urm!=NULL; u=u->urm);
  28.       u->urm=q;///leg elemente existe de noul nod
  29.   }
  30. }
  31.  
  32. void Creare(nod*&p)
  33. {
  34.    ifstream fin("lista.in");
  35.    int x;
  36.    while(fin>>x)
  37.         adaugare(p,x);
  38.     fin.close();
  39. }
  40.  
  41. void afisare(nod*p)
  42. {
  43.     for(nod *q=p;q; q=q->urm)
  44.         cout<<q->info<<" ";
  45.     cout<<"\n";
  46. }
  47.  
  48.  
  49. int main()
  50. {
  51.   Creare(p);
  52.   afisare(p);
  53.   return 0;
  54. }
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement