Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdafx.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <malloc.h>
  5. struct list{
  6.     int data;
  7.     struct list * next;
  8. };
  9.  
  10. int main(){
  11.     struct list * first1 = NULL;
  12.     struct list * first2 = NULL;
  13.  
  14.     for (int i = 0; i < 100; i++){
  15.         struct list * p1 = (struct list *) malloc (sizeof(struct list));
  16.         p1->data = i;
  17.         p1->next = NULL;
  18.  
  19.         if (first1 == NULL) first1 = p1;
  20.         else {
  21.             struct list * cur = first1;
  22.  
  23.             while (cur->next!= NULL) cur = cur->next;
  24.             cur->next = p1;
  25.             }
  26.         }
  27.  
  28.     for (int i = 0; i < 30; i++){
  29.         struct list * p2 = (struct list *) malloc (sizeof(struct list));
  30.         p2->data = i;
  31.         p2->next = NULL;
  32.  
  33.         if (first2 == NULL) first2 = p2;
  34.         else {
  35.             struct list * cur = first2;
  36.  
  37.             while (cur->next != NULL) cur = cur->next;
  38.             cur->next = p2;
  39.         }
  40.     }
  41.    
  42.     struct list * cur = first1;
  43.     struct list * cur1 = first1;
  44.    
  45.     while (cur->next != NULL) cur = cur->next;
  46.    
  47.     cur->next = first2;
  48.     while (cur1 != NULL){
  49.         std::cout<<cur1->data<<" ";
  50.         cur1 = cur1->next;
  51.     }
  52.  
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement