|  | 
 
| 
#include<iostream>
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  #include<cstdlib>
 #include<iomanip>
 using namespace std;
 
 #define OK 1
 #define ERROR 0
 
 typedef int Starus;
 typedef int ElemType;
 
 typedef struct LNode{
 ElemType data;
 struct LNode *next;
 }LNode, *LinKlist;
 
 ElemType survial;
 
 Status InitList_CL(LinKlist &L){
 L=new LNode;
 L->next=L;
 L->data=0;
 return OK;
 }
 
 void CreateCL_Rear(LinKlist &L, int n){
 int i;
 LinKlist p,r;
 
 if(n<1) return;
 r=L;
 cout<<"The sequence of n slaves:\n";
 for(i=1;i<=n;i++){
 p=new LNode;
 p->data=i;
 cout<<setw(3)<<i<<" ";
 p->next=NULL;
 r->next=p;
 r=p;
 L->data++;
 }
 cout<<endl<<endl;
 r->next=L->next;
 }
 
 Status CLDelete(LinKlist &L,int m) {
 LinKlist p,q;
 int i;
 
 p=L->next;
 cout<<"The killed sequence of n slaves :\n";
 while(L->data>0){
 for(i=1;i<m-1;i++)
 p=p->next;
 
 cout<<setw(3)<<p->next->data<<" ";
 q=p->next;
 p->next=q->next;
 delete q;
 p=p->next;
 L->data--;
 if(L->data==1) survival=p->data;
 }
 cout<<endl<<endl;
 L->next=L;
 return OK;
 }
 
 int main(){
 LinKlist L;
 int Status_value,n=1,m=2;
 
 do{
 cout<<"Please input the number n of slaves(must n>0):"<<endl;
 cin>>n;
 }
 while(n<1);
 
 do{
 cout<<"\nPlease input the count m for kill slaves (must m>1) :"<<endl;
 cin>>m;
 }while(m<2);
 cout<<endl<<endl;
 
 status_value=InitList_CL(L);
 CreateCL_Rear(L,n);
 status_value=CLDelete(L,m);
 cout<<"\nThe survival of n slaves is the "<<survival<<"-th slave.\n\n";
 system("pause");
 return 0;
 }
 
 
拼写错误 
多多检查下 复制代码#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status; // 这里 
typedef int ElemType;
typedef struct LNode{
        ElemType data;
        struct LNode *next;
}LNode, *LinKlist;
ElemType survival; // 这里 
Status InitList_CL(LinKlist &L){
           L=new LNode;
           L->next=L;
           L->data=0;
           return OK;
}
void CreateCL_Rear(LinKlist &L, int n){
int i;
LinKlist p,r;
if(n<1) return;
r=L;
cout<<"The sequence of n slaves:\n";
for(i=1;i<=n;i++){
    p=new LNode;
    p->data=i;
    cout<<setw(3)<<i<<" ";
    p->next=NULL;
    r->next=p;
    r=p;
    L->data++;
     }
     cout<<endl<<endl;
     r->next=L->next;
}
Status CLDelete(LinKlist &L,int m) {
  LinKlist p,q;
  int i;
  p=L->next;
  cout<<"The killed sequence of n slaves :\n";
  while(L->data>0){
    for(i=1;i<m-1;i++)
        p=p->next;
    cout<<setw(3)<<p->next->data<<" ";
    q=p->next;
    p->next=q->next;
    delete q;
    p=p->next;
    L->data--;
    if(L->data==1) survival=p->data;
  }
  cout<<endl<<endl;
  L->next=L;
  return OK;
}
int main(){
LinKlist L;
int status_value,n=1,m=2; //这里 
do{
    cout<<"Please input the number n of slaves(must n>0):"<<endl;
    cin>>n;
}
while(n<1);
do{
    cout<<"\nPlease input the count m for kill slaves (must m>1) :"<<endl;
    cin>>m;
}while(m<2);
cout<<endl<<endl;
status_value=InitList_CL(L);
CreateCL_Rear(L,n);
status_value=CLDelete(L,m);
cout<<"\nThe survival of n slaves is the "<<survival<<"-th slave.\n\n";
system("pause");
return 0;
}
 | 
 |