Advertisement
Guest User

ponter 01

a guest
Jan 22nd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdio.h>
  3.  
  4. struct mylist
  5. {
  6.     int data;
  7.     struct mylist*next;
  8.  
  9. };
  10. struct mylist* head=NULL;
  11.  
  12. void display()
  13. {
  14.     struct mylist*temp=head;
  15.     while (temp!=NULL)
  16.     {
  17.         printf("%d->",temp->data);
  18.         temp=temp->next;
  19.     }
  20. }
  21. void insert_first(int data)
  22. {
  23.     struct mylist*temp=head;
  24.     struct mylist*new_node=(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.     new_node->data=data;
  34.      new_node->next=NULL;
  35.      if(temp=NULL)
  36.      {
  37.          head=new_node;
  38.          return;
  39.      }
  40.      while(temp->next!=NULL)
  41.      {
  42.          temp=temp->next;
  43.  
  44.      }
  45.      temp->next=new_node;
  46.      return;
  47.  
  48. }
  49. void creat(int data)
  50. {
  51.     insert_last(data);
  52. }
  53. int main()
  54. {
  55.     insert_last(5);
  56.      insert_last(7);
  57.      display();
  58.  
  59.      return 0;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement