Advertisement
Dani_info

Parcuregre si creare

Oct 27th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct nod{
  6.     int info;
  7.     nod* leg;
  8. };
  9.  
  10. nod* creare (){
  11.     nod *prim;
  12.     int nr;
  13.     cin>>nr;
  14.     if (nr == 0)
  15.         return 0;
  16.     else{
  17.         nod *p=new nod;
  18.         prim=p;
  19.         p->info=nr;
  20.         p->leg=NULL;
  21.         cin>>nr;
  22.         while (nr){
  23.             nod *q=new nod;
  24.             q->info=nr;
  25.             p->leg=q;
  26.             p=q;
  27.             cin>>nr;
  28.         }
  29.         p->leg=NULL;
  30.     }
  31.     return prim;
  32. }
  33.  
  34. void parcurgere (nod *prim){
  35.     nod *p=prim;
  36.     while (p){
  37.         cout<<p->info<<endl;
  38.         p=p->leg;
  39.     }
  40. }
  41. int main()
  42. {
  43.     nod *p = creare();
  44.     parcurgere (p);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement