Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int a;
- struct node *next;
- }node;
- node *head=NULL, *list=NULL;
- void insert_at_nth(int a)
- {
- node *N=(node*)malloc(sizeof(node));
- N->a=a;
- N->next=NULL;
- int n;
- scanf("%d", &n);
- if(head==NULL)
- {
- head=N;
- return;
- }
- else
- {
- list=head;
- n=n-2;
- while(n!=0)//while(p--)
- {
- list=list->next;
- }
- N->next=list->next;
- list->next=N;
- }
- }
- void display()
- {
- list=head;
- while(list!=NULL)
- {
- printf("Data = %d\n", list->a);
- list=list->next;
- }
- }
- int main()
- {
- int a,x,n;
- scanf("%d", &a);
- while(a--)
- {
- scanf("%d", &x);
- insert_at_nth(x);
- }
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement