Advertisement
Guest User

Untitled

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