Susri

doublystring

Apr 3rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5.     char data[60];
  6.     struct node *prev;
  7.     struct node *next;
  8. };
  9. struct node *head=NULL;
  10. struct node *last=NULL;
  11. struct node *current=NULL;
  12. void insert(char* data)
  13. {
  14.     struct node *temp=(struct node*)malloc(sizeof(struct node));
  15.     strcpy(temp->data,data);
  16.     temp->prev=NULL;
  17.     temp->next=NULL;
  18.     if(head==NULL)
  19.     {
  20.         head=temp;
  21.         return;
  22.     }
  23.     current=head;
  24.     while(current->next!=NULL)
  25.     {
  26.     current=current->next;
  27.     }
  28.     current->next=temp;
  29.     last=temp;
  30.     temp->prev=current;
  31.  
  32. }
  33. void print()
  34. {
  35.     struct node *ptr=head;
  36.     printf("linked list is : ");
  37.     while(ptr->next!=NULL)
  38.     {
  39.         printf("%s ",ptr->data);
  40.         ptr=ptr->next;
  41.     }
  42.     printf("%s",ptr->data);
  43. }
  44. void main()
  45. {
  46.     insert("susri");
  47.     insert("rowshon");
  48.     print();
  49.     return 0;
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment