Advertisement
rony-Rony_05

insert first doubly

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