#include <iostream>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
typedef struct LNode
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int data;
struct LNode *link;
}LNode, *LinkList;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
void JosePhus(int n, int k, int m)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
LinkList p,r,curr;
p=(LNode*)malloc(sizeof(LNode));
p->data=1;
p->link=p;
curr=p;
for (int i=2;i<n+1;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
LNode *t=(LNode*)malloc(sizeof(LNode));
t->data=i;
t->link=curr->link;
curr->link=t;
curr=t;
}
while (--k)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
p=p->link;
}
while (n--)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for (int i=m;--i;r=p,p=p->link);
r->link=p->link;
printf("%d->",p->data);
free(p);
p=r->link;
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main(int argc, char* argv[])
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
printf("Hello World!\n");
JosePhus(13,4,2);
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
posted on 2009-07-19 11:34
老马驿站 阅读(97)
评论(0) 编辑 收藏 引用 所属分类:
c++