Advertisement
luluinstalock

Untitled

Jan 31st, 2016
1,787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Node{
  5.     int x;
  6.     struct Node *next;
  7. };
  8.  
  9. void wyswietl( struct Node *head ){
  10.     while( head != NULL){
  11.     printf("%d\n", head->x);
  12.    
  13.     head=head->next;
  14.     }
  15. }
  16.  
  17. int main(){
  18.     struct Node *head;
  19.     head = malloc(sizeof(struct Node));
  20.    
  21.    
  22.    
  23.     struct Node *tail;
  24.    
  25.     tail=head;
  26.  
  27.    
  28.     for(int i=-20;i<21;i=i+5){
  29.         struct Node *tmp;
  30.         tmp = malloc(sizeof(struct Node));
  31.         tmp->x = i;
  32.        
  33.         tail->next=tmp;
  34.         tmp->next=NULL;
  35.         tail=tmp;
  36.        
  37.     }
  38.    
  39.     wyswietl( head);
  40.    
  41.     while (head != NULL){
  42.         struct Node *tmp = head;
  43.         tmp=head->next;
  44.         free(head);
  45.         head=tmp;
  46.     }
  47.      
  48.    
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement