Advertisement
Guest User

dst aivabe hobe ki

a guest
Nov 11th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct ptr
  4. {
  5.     int a;
  6.     struct ptr*pt;
  7. } ptr;
  8. ptr*temp=NULL;
  9. void insrtat_nth()
  10. { int pos;
  11.     scanf("%d",&pos);
  12.      ptr*N=(ptr*)malloc(sizeof(ptr));
  13.     scanf("%d",&N->a);
  14.     N->pt=NULL;
  15.     if(pos==1)
  16.     { N->pt=temp;
  17.         temp=N;
  18.     }
  19.     else
  20.     {ptr*list=temp,*head;
  21.         pos=pos-2;
  22.         while(pos-- && list->pt!=NULL)
  23.         {
  24.            list=list->pt;
  25.  
  26.         }
  27.        list->pt=N;
  28.         N->pt=temp;
  29.     }
  30.  
  31.  
  32. }
  33. void insertend()
  34. {
  35.     ptr*N=(ptr*)malloc(sizeof(ptr));
  36.     scanf("%d",&N->a);
  37.     N->pt=NULL;
  38.     if(temp==NULL)
  39.     {
  40.         temp=N;
  41.     }
  42.     else
  43.     {
  44.         ptr*list=temp;
  45.         while(list->pt!=NULL)
  46.         {
  47.             list=list->pt;
  48.         }
  49.         list->pt=N;
  50.  
  51.     }
  52. }
  53. void display()
  54. {
  55.     ptr*list=temp;
  56.     while(list!=NULL)
  57.     {
  58.         printf("%d ",list->a);
  59.         list=list->pt;
  60.     }
  61. }
  62. int main()
  63. {
  64.     int n,x,y;
  65.     scanf("%d",&n);
  66.     while(n--)
  67.     {
  68.         insertend();
  69.     }
  70.     insrtat_nth();
  71.     display();
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement