Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  2-1
Language: C/C++
Code:
#include<stdio.h>
#include<malloc.h>
#define maxsize 1000
typedef int ElemType;
typedef struct List
{
  ElemType data[maxsize];
  int length;
}*SqList;
 SqList InitList( )
{             SqList L;
     L=(SqList )malloc(sizeof(List));
     return L;
}
void CreateList(SqList L)
{
     int i,n;
printf("总序号为:");
scanf("%d",&n);
     for(i=0;i<n;i++)
     {
          L->data[i]=i+1;
     printf("%d",L->data[i]);
     }
     L->length=n;
}
void josephus(SqList L)
{
     int i,j,t,m;
     t=0;   
     printf("出列序号为:");
     scanf("%d",&m); 
               printf("出列顺序:n");
     for(i=L->length;i>=1;i--)
     {
          t=(t+m-1)%i;
          printf("%d",L->data[t]);
          for(j=t+1;j<=i-1;j++)
          L->data[j-1]=L->data[j];
     }
}
void main()
{  
    SqList  L;
     L=InitList();
    CreateList(L);  
     josephus(L);
}
          
Comments: