Advertisement
Guest User

data structure

a guest
Jan 22nd, 2020
140
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. struct mylist
  4.  
  5. {
  6.     int data ;
  7.     struct mylist*next;
  8.  
  9. };
  10. struct mylist*head=NULL;
  11. void display()
  12. {
  13.  
  14.     struct mylist*temp=head;
  15.     while (temp!=NULL)
  16.     {
  17.         printf("%d->",temp->data);
  18.         temp=temp->next;
  19.     }
  20.     printf("\n");
  21. }
  22. void insert_first(int data)
  23. {
  24.     struct mylist*temp=(struct mylist*)malloc(sizeof(struct mylist));
  25.     temp->data=data;
  26.     temp->next=head;
  27.     head=temp;
  28. }
  29. void insert_last(int data)
  30. {
  31.     struct mylist*temp=head;
  32.     struct mylist*new_node=(struct mylist*)malloc(sizeof(struct mylist));
  33.  
  34.     new_node->data=data;
  35.     new_node->next=NULL;
  36.     if (temp==NULL)
  37.     {
  38.     head=new_node;
  39.         return;
  40.     }
  41.     while(temp->next!=NULL)
  42.     {
  43.         temp=temp->next;
  44.     }
  45.     temp->next=new_node;
  46.  
  47.     return;
  48. }
  49.  
  50. void creat(int data)
  51. {
  52.     insert_last(data);
  53.  
  54. }
  55. int main()
  56. {
  57.     insert_last(5);
  58.     insert_last(10);
  59.     display();
  60.     return 0;
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement