Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define ui_T int
  4.  
  5. struct node
  6. {
  7.     int val;
  8.     node* next;
  9. };
  10.  
  11. void add(node** L,ui_T valoare)
  12. {
  13.     node* newN = new node;
  14.     newN->val = valoare;
  15.     newN->next=NULL;
  16.  
  17.     if(*L==NULL)
  18.     {
  19.         *L=newN;
  20.         return;
  21.     }
  22.    
  23.     node* p= *L ;
  24.  
  25.     while(p!=NULL)
  26.         p=p->next;
  27.  
  28.     p=newN;
  29.  
  30. }
  31.  
  32. void read(node* L)
  33. {
  34.     ui_T valoare,n;
  35.     cin>>n;
  36.     for(ui_T i=0;i<n;i++)
  37.         {cin>>valoare;
  38.         add(&L,valoare);
  39.         }
  40.  
  41.     while(L)
  42.        {
  43.         cout<<L->val;
  44.         L=L->next; }
  45. }
  46. int main ()
  47. {
  48. node* L;
  49. read(L);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement