我采用的是循环链表的方法,没遇到一个符合的数,则就删除这个数。继续读取下一个数。
首先创建链表:
给这个链表节点的赋值分别从0到n-1。
由于是循环链表,最后的节点需要指向头结点。
我这个头结点不仅仅是指针,还有数据。
#include <iostream>
using namespace std;
typedef struct LinkNode
{
int data;
struct LinkNode *next;
}node;
node *create(int n)
{
node *head = new node();
head->data = 0;
node *p;
p = head;
int m= n-1;
int i =1;
while(m)
{
node *s = new node();
s->data = i;
p->next = s;
p = s;
i++;
m--;
}
p->next = head;
return head;
}
寻找每个适合的节点
每次都从0读取,0 ,1,2,3 需要读4个节点。
判断是不是组后一个节点是 p->next = p;
void findx(int n)
{
node *head;
head = create(n);
node *p;
int i;
while(head&&(head->next != head))
{
i = 0;
while(head&&((i