Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct ptr
- {
- int a;
- struct ptr*pt;
- } ptr;
- ptr*temp=NULL;
- void insrtat_nth()
- { int pos;
- scanf("%d",&pos);
- ptr*N=(ptr*)malloc(sizeof(ptr));
- scanf("%d",&N->a);
- N->pt=NULL;
- if(pos==1)
- { N->pt=temp;
- temp=N;
- }
- else
- {ptr*list=temp,*head;
- pos=pos-2;
- while(pos-- && list->pt!=NULL)
- {
- list=list->pt;
- }
- list->pt=N;
- N->pt=temp;
- }
- }
- void insertend()
- {
- ptr*N=(ptr*)malloc(sizeof(ptr));
- scanf("%d",&N->a);
- N->pt=NULL;
- if(temp==NULL)
- {
- temp=N;
- }
- else
- {
- ptr*list=temp;
- while(list->pt!=NULL)
- {
- list=list->pt;
- }
- list->pt=N;
- }
- }
- void display()
- {
- ptr*list=temp;
- while(list!=NULL)
- {
- printf("%d ",list->a);
- list=list->pt;
- }
- }
- int main()
- {
- int n,x,y;
- scanf("%d",&n);
- while(n--)
- {
- insertend();
- }
- insrtat_nth();
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement