SAADQUAMER

Untitled

Oct 12th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include<stdlib.h>
  2.  
  3. typedef struct node
  4. {
  5.     int a;
  6.     char ch;
  7.     struct node *next;
  8.  
  9. } node;
  10.  
  11.  
  12. node *head;
  13.  
  14.  
  15. void display()
  16. {
  17.  
  18.     node *list=head;
  19.     while(list !=NULL)
  20.     {
  21.         printf("\n\nA= %d ,C= %c\n",list->a,list->ch);
  22.  
  23.  
  24.         list=list->next;
  25.  
  26.     }
  27. }
  28.  
  29.  
  30. void insert_end(int aN,char chN)
  31. {
  32.     node *N=(node*)malloc(sizeof(node));
  33.     N->a=aN;
  34.     N->ch=chN;
  35.     N->next=NULL;
  36.     node *list=head;
  37.     if(head==NULL)
  38.     {
  39.         head=N;
  40.         list=N;
  41.     }
  42.     else
  43.     {
  44.         while(list->next!=NULL)
  45.         {
  46.             list=list->next;
  47.         }
  48.         list->next=N;
  49.  
  50.     }
  51.  
  52. }
  53.  
  54.  
  55. void insert_nth(int n,int aN,char chN)
  56. {
  57.     node *N=(node*)malloc(sizeof(node));
  58.     N->a=aN;
  59.     N->ch=chN;
  60.     N->next=NULL;
  61.     if(n==1)
  62.     {
  63.         N->next=head;
  64.         head=N;
  65.         return;
  66.     }
  67.     else
  68.     {
  69.         node*list=head;
  70.         n=n-2;
  71.         while(n!=0&&list->next!=NULL)
  72.         {
  73.             list=list->next;
  74.             n--;
  75.         }
  76.         N->next=list->next;
  77.         list->next=N;
  78.     }
  79. }
  80. int main()
  81. {
  82.     head=NULL;
  83.     int x,af,l;
  84.     char cf;
  85.     insert_end(2,'d');
  86.     insert_end(4,'h');
  87.     insert_end(3,'f');
  88.     insert_end(8,'e');
  89.     printf("INPUT FOR nTH Position\n");
  90.     scanf("%d",&x);
  91.     scanf("%d",&l);
  92.     scanf(" %c",&cf);
  93.     insert_nth(x,l,cf);
  94.     display();
  95.     return 0;
  96.     }
Advertisement
Add Comment
Please, Sign In to add comment