- #include<iostream.h>
- struct student
- {
- int rank;
- student *next;
- };
- student *final;
- student *creat(int i)
- {
- student *head,*p1,*p2;
- int n=1;
- p1=new(student);
- head=p1;
- p2=p1;
- p1->rank=n;
- cout<<"Construct the "<<n<<"th unit"<<endl<<endl;
- while(n!=i)
- {
- ++n;
- p1=new(student);
- p1->rank=n;
- cout<<"Construct the "<<n<<"th unit"<<endl<<endl;
- p2->next=p1;
- p2=p1;
- }
- delete(p1);
- p2->next=head;
- return head;
- }
- void fun(student *head,int j)
- {
- student *p;
- student *n;
- n=head;
- if(n==n->next)
- { final=n->next;
- return;
- }
- int round=j;
- while(round)
- {
- round--;
- p=n;
- n=p->next;
- }
- p->next=n->next;
- cout<<"Delete the "<<n->rank<<"th unit"<<endl<<endl;
- delete n;
- fun(p->next,j);
- }
- int main()
- {
- student *head1;
- int i,j;
- cout<<"Please input the number:";
- cin>>i;
- head1=creat(i);
- cout<<"Please input the key:";
- cin>>j;
- fun(head1,j);
- cout<<"Remaining the "<<final->rank<<"th unit"<<endl;
- return 0;
- }