I have written algorithm, called function of Joseph. Sense such that N = 9, M = 5. Let's say there are 9 people in the circle, and after each 5 are brought together a number of removal. As a result, there will be one. Do not understand the first 2 rows int N = atoi (argv [1]);
int M = atoi (argv [2]);
that they fulfill? And where you want to assign N = 9, M = 5?
usingnamespace std;
struct note
{
int item;
note*next;
note(int x, note*t):item(x),next(t){}
};
typedef note*link;
auto main(int argc, char*argv[])->int
{
int N = atoi(argv[1]);
int M = atoi(argv[2]);
link t = new note(1,0);
t->next = t;
link x = t;
for (int i = 2; i <= N; ++i)
x = (x->next = new note(i, t));
while (x != x->next)
{
for (int i = 1; i < M; ++i)
x = x->next;
}
cout << x->item << endl;
return 0;
}
The program is using command line arguments to pass the desired values to the program. The atoi() calls convert the second and third C-strings that are in the argument list to integers.
You would call the program using this syntax: YourProgramName 9 5