Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 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. void main(){
  11.     struct list * first = NULL;
  12.    
  13.     for (int i = 0; i < 50; i++){
  14.         struct list * ml = NULL;
  15.         ml=(struct list *) malloc (sizeof(struct list));
  16.         ml->data = i;
  17.         ml->next = NULL;
  18.  
  19.         if (first == NULL) first = ml;
  20.         else {
  21.             struct list * cur = first;
  22.            
  23.             while (cur != NULL){
  24.                 cur = cur->next;
  25.                 cur->next = ml;
  26.             }
  27.         }
  28.     }
  29.     struct list * cur = first;
  30.     while (cur->next != NULL){
  31.         std::cout<<cur->data;
  32.         cur = cur->next;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement