Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  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.     node* a;
  27.     a = NULL;
  28.     add(a, 10);
  29.     cout<<a->val;
  30.  
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement