Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. struct node{
  6.     int val;
  7.     node* next;
  8. };
  9.  
  10. void add(node *&test, int a ){
  11.     node* temp = new node;
  12.     temp->val =a;
  13.     temp->next = NULL;
  14.     if(test==NULL){
  15.         test=temp;
  16.     }else{
  17.         node* t = test;
  18.         while(t->next!=NULL){
  19.             t=t->next;
  20.         }
  21.         t->next = temp;
  22.     }
  23. }
  24.  
  25. int main(){
  26.     srand (time(NULL));
  27.     node* a;
  28.     a = NULL;
  29.     add(a, 10);
  30.    
  31.     for(int i = 0; i<10; i++){
  32.         add(a, rand()%50);
  33.     }
  34.     while(a->next!=NULL){
  35.         cout<<a->val<<endl;
  36.         a=a->next;
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement