#include<iostream>
#include<iomanip>
using namespace std;
typedef struct{
int a;
}Book;
typedef struct LNode{
Book data;
struct LNode *next;
}LNode,*LinkList;
void InitList(LinkList &L){
L=new LNode;
L->next=L;
}
void CreateList(LinkList &L,int m){
LinkList p,r;
r=L;
for(int i=1;i<=m;i++){
p=new LNode;
p->data.a=i;
r->next=p;
p->next=L->next;
r=p;
}
}
void PrintList(LinkList &L,int m,int n){
LinkList p,q;
p=L;
int a=1;
for(int i=1;i<=m;i++){
if(a>m) break;
else if(i!=n) p=p->next;
else if(i==n){
cout<<p->next->data.a<<' ';
q=p->next;
p->next=q->next;
p=q;
i=0;
a++;
}
}
cout<<endl;
}
int main(){
int m,n;
LinkList L;
do{
cin>>m>>n;
if(m==0&&n==0)break;
InitList(L);
CreateList(L,m);
PrintList(L,m,n);
}while(true);
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/39389.html
標籤:基礎類
下一篇:C++資料結構求解
