Advertisement
luluinstalock

Untitled

Feb 8th, 2016
1,772
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 display(struct Node *head){
  10.     while(head!=NULL){
  11.         printf("%d \n", head->x);
  12.         head=head->next;
  13.     }
  14. }
  15.  
  16. int main(){
  17.     struct Node *head;
  18.     head = malloc(sizeof(struct Node));
  19.    
  20.     struct Node *tail;
  21.     tail=head;
  22.    
  23.     for(int i=-20;i<21;i=i+5){
  24.         struct Node *tmp;
  25.         tmp=malloc(sizeof(struct Node));
  26.         tmp->x = i;
  27.        
  28.         tail->next=tmp;
  29.         tmp->next=NULL;
  30.         tail=tmp;
  31.     }
  32.     display(head);
  33.    
  34.     while(head!=NULL){
  35.         struct Node *tmp = head;
  36.         tmp=head->next;
  37.         free(head);
  38.         head=tmp;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement