Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct list
  5. {
  6.     int num;
  7.     double data;
  8.     struct list *next;
  9. }node;
  10.  
  11. void insert(node *s, int num, double data)
  12.     {
  13.         while(s->next != NULL)
  14.         {
  15.             s = s->next;
  16.         }
  17.         s->next = (node*) malloc(sizeof(node));
  18.         s->next->num = num;
  19.         s->next->data = data;
  20.         s->next->next = NULL;
  21.     }
  22.  
  23. void display(node *s)
  24.     {
  25.         while(s->next != NULL)
  26.         {
  27.             printf("%d %.1f\n",s->next->num, s->next->data);
  28.             s = s->next;
  29.         }
  30.     }
  31. int main()
  32.     {
  33.         node *head1 = (node*) malloc(sizeof(node));
  34.         node *head2 = (node*) malloc(sizeof(node));
  35.         head1->next = head2;
  36.         head2->next = NULL;
  37.  
  38.  
  39.  
  40.         /*Inserting Data*/
  41.         printf("======Inserting data=========\n");
  42.         insert(head1,4, 1.2);
  43.         insert(head2,7, 1.8);
  44.  
  45.  
  46.         /*Displaying Data*/
  47.         display(head1);
  48.  
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement