Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- typedef struct node
- {
- int a;
- char ch;
- struct node *next;
- } node;
- node *head;
- void display()
- {
- node *list=head;
- while(list !=NULL)
- {
- printf("\n\nA= %d ,C= %c\n",list->a,list->ch);
- list=list->next;
- }
- }
- void insert_end(int aN,char chN)
- {
- node *N=(node*)malloc(sizeof(node));
- N->a=aN;
- N->ch=chN;
- N->next=NULL;
- node *list=head;
- if(head==NULL)
- {
- head=N;
- list=N;
- }
- else
- {
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=N;
- }
- }
- void insert_nth(int n,int aN,char chN)
- {
- node *N=(node*)malloc(sizeof(node));
- N->a=aN;
- N->ch=chN;
- N->next=NULL;
- if(n==1)
- {
- N->next=head;
- head=N;
- return;
- }
- else
- {
- node*list=head;
- n=n-2;
- while(n!=0&&list->next!=NULL)
- {
- list=list->next;
- n--;
- }
- N->next=list->next;
- list->next=N;
- }
- }
- int main()
- {
- head=NULL;
- int x,af,l;
- char cf;
- insert_end(2,'d');
- insert_end(4,'h');
- insert_end(3,'f');
- insert_end(8,'e');
- printf("INPUT FOR nTH Position\n");
- scanf("%d",&x);
- scanf("%d",&l);
- scanf(" %c",&cf);
- insert_nth(x,l,cf);
- display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment