Last active
August 8, 2017 17:30
-
-
Save PoojaB26/4d8569e4e504d8a00bd2ad375dcc48ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
typedef struct n{ | |
int data; | |
struct n* next; | |
}node; | |
node* root=NULL; | |
node* makenull(){ | |
node* nwd=(node*)malloc(sizeof(node)); | |
nwd->next=NULL; | |
return nwd; | |
} | |
void insert(int info){ | |
node* nw=makenull(); | |
if(root==NULL){ | |
nw->data=info; | |
root=nw; | |
} | |
else{ | |
nw->data=info; | |
node *p=root; | |
node* q; | |
while(p!=NULL){ | |
q=p; | |
p=p->next; | |
} | |
q->next=nw; | |
} | |
} | |
void moveToFirst(node *head){ | |
node *p=root; | |
node* q=NULL; | |
while(p->next!=NULL){ | |
p=p->next; | |
} | |
p->next=head; | |
root=head->next; | |
head->next=NULL; | |
} | |
void printList(node *nod) | |
{ | |
while(nod->next != NULL) | |
{ | |
printf("%d\n", nod->data); | |
nod = nod->next; | |
} | |
printf("%d\n", nod->data); | |
} | |
int main(){ | |
int n,i,dist; | |
scanf("%d",&n); | |
scanf("%d",&dist); | |
for(i=1;i<=n;i++) | |
insert(i); | |
for(i=0;i<(dist-n);i++) | |
moveToFirst(root); | |
printList(root); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment