Advertisement
afrinahoque

LinkedListFunction2.c

Sep 24th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct node
  4. {
  5.     int a;
  6.     char ch;
  7.     struct node *next;
  8. }node;
  9.  
  10. node *head;
  11.  
  12. void insert_at_first(int aN, char chN)
  13. {
  14.     node *N=(node*)malloc(sizeof(node));
  15.     N->a=aN;
  16.     N->ch=chN;
  17.     N->next=NULL;
  18.  
  19.     if(head==NULL)
  20.     {
  21.         head=N;
  22.         return;
  23.     }
  24.     N->next=head;
  25.  
  26.     head=N;
  27. }
  28.  
  29. void Display()
  30. {
  31.     node *list;
  32.     while(list!=NULL)
  33.     {
  34.         printf("A:%d\n", list->a);
  35.         printf("CH:%c\n", list->ch);
  36.         printf("\n");
  37.  
  38.         list=list->next;
  39.     }
  40. }
  41.  
  42. int main()
  43. {
  44.     head=NULL;
  45.     insert_at_first(5, 'x');
  46.     insert_at_first(4, 'y');
  47.     insert_at_first(3, 'z');
  48.     insert_at_first(9, 'i');
  49.  
  50.     Display();
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement