Advertisement
rony-Rony_05

doubly last

Oct 12th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 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_end(int aN,char chN)
  28. {
  29.  
  30.     node*N=(node*)malloc(sizeof(node));
  31.     N->a=aN;
  32.     N->ch=chN;
  33.     N->next=NULL;
  34.     N->previous=NULL;
  35.     node*list=head;
  36.     if(head==NULL)
  37.     {
  38.         head=N;
  39.     }
  40.     else
  41.     {
  42.         while(list->next!=NULL)
  43.         {
  44.             list=list->next;
  45.             N->previous=list;
  46.         }
  47.         list->next=N;
  48.         N->next=NULL;
  49.         N->previous=list;
  50.  
  51.  
  52.     }
  53.  
  54. }
  55.  
  56. int main()
  57. {
  58.     head=NULL;
  59.     insert_at_end(1,'A');
  60.     insert_at_end(3,'b');
  61.     insert_at_end(5,'c');
  62.     insert_at_end(7,'d');
  63.     insert_at_end(9,'e');
  64.     display();
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement