文章
145
粉丝
217
获赞
21
访问
84.1k
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node *next;
}LNode,*LinkList;
//建立无头循环链表
void InitList(LinkList &L,int n)
{
L = (LNode *)malloc(sizeof(LinkList));
L = NULL;
int i;
struct node *t;
for(i = n; i >= 1; i--)
{
struct node *p = new LNode();
p->data = i;
if(!L)
{
L = p;
L->next = NULL;
t = L;
}
else
{
p->next = L;
L = p;
}
}
t->next = L;
}
//报数
void CountList(LinkList &L,int index[],int s,int m)
{
struct node *pre = L,*p;
p = L->next;
int i = 1,j = 0;
if(s > 1)
{
while(i < s-1)
{
pre = p;
p = p->next;
i++;
}
}
else
p = L;
while(1)
{
int k = 1;
while(k < m)
{
pre = p;
p = p->next;
k++;
}
index[j++] = p->data;
pre->next = p->next;
p = pre->next;
if(pre == p)
break;
}
index[j] = p->data;
}
int main()
{
in...
登录后发布评论
暂无评论,来抢沙发