Advertisement
afrinahoque

Run hoyna ken:3

Oct 1st, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct node
  4. {
  5.     int a;
  6.     struct node *next;
  7. }node;
  8.  
  9. node *head=NULL, *list=NULL;
  10.  
  11. void insert_at_nth(int a)
  12. {
  13.  
  14.     node *N=(node*)malloc(sizeof(node));
  15.     N->a=a;
  16.     N->next=NULL;
  17.  
  18.     int n;
  19.     scanf("%d", &n);
  20.  
  21.     if(head==NULL)
  22.     {
  23.         head=N;
  24.         return;
  25.     }
  26.     else
  27.     {
  28.         list=head;
  29.         n=n-2;
  30.         while(n!=0)//while(p--)
  31.         {
  32.             list=list->next;
  33.         }
  34.         N->next=list->next;
  35.         list->next=N;
  36.     }
  37. }
  38.  
  39. void display()
  40. {
  41.     list=head;
  42.     while(list!=NULL)
  43.     {
  44.         printf("Data = %d\n", list->a);
  45.         list=list->next;
  46.     }
  47. }
  48.  
  49. int main()
  50. {
  51.     int a,x,n;
  52.     scanf("%d", &a);
  53.     while(a--)
  54.     {
  55.         scanf("%d", &x);
  56.         insert_at_nth(x);
  57.     }
  58.     display();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement