What does this expression mean?


Below is the JOSEPHUS round table sample codes I am studying.

The for loop expression "for(int s=m-1;s--;r=p,p=p->link);" is unusual to me. Shouldn't "r=p,p=p->link" be a conditional expression to stop the for loop?
why there is a comma "," after "r=p"? How to interpret this for loop expression?

Thanks,

L
--------------------

#include <iostream>

using namespace std;

typedef struct LNode
{
int data;
struct LNode *link;
}LNode,*LinkList;


void JOSEPHUS(int n,int k,int m)
{

LinkList p,r,list,curr;

p=(LinkList)malloc(sizeof(LNode));
p->data=1;
p->link=p;
curr=p;
for(int i=2;i<=n;i++)
{
LinkList t=(LinkList)malloc(sizeof(LNode));
t->data=i;
t->link=curr->link;
curr->link=t;
curr=t;
}

r=curr;
while(k--)
r=p,p=p->link;
while(n--)
{
for(int s=m-1;s--;r=p,p=p->link);
r->link=p->link;
printf("%d->",p->data);
free(p);
p=r->link;
}
}

int main(int argc, const char * argv[]) {

JOSEPHUS(5,2,3);
return 0;
}
Topic archived. No new replies allowed.