SAADQUAMER

Untitled

Oct 8th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct node
  4. {
  5.     int a;
  6.     char ch;
  7.     struct node *next;
  8. } node;
  9.  
  10.  
  11.  node*head=NULL;
  12. void insert_nth(int n,int aN,char chN)
  13. {
  14.     node *N=(node*)malloc(sizeof(node));
  15.     N->a=aN;
  16.     N->ch=chN;
  17.     N->next=NULL;
  18.     if(n==1)
  19.     {
  20.         N->next=head;
  21.         head=N;
  22.         return;
  23.     }
  24.     else
  25.     {
  26.         node*list=head;
  27.         n=n-2;
  28.         while(n!=0&&list->next!=NULL)
  29.         {
  30.             list=list->next;
  31.             n--;
  32.         }
  33.         N->next=list->next;
  34.         list->next=N;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment