文章
6
粉丝
94
获赞
1
访问
3.9k
#include<iostream>
using namespace std;
int main(){
struct Node {
int n;
struct Node * next;
};
int N;
cin>>N;
//构建循环链表
struct Node *p,*q,*h,*t;
p = new Node;
h=p;
for (int i = 1; i <=N ; i++) {
p->n=i;
q = new Node;
p->next = q;
t=p; //记录结尾
p=q;
}
t->next = h; //形成闭环
//从1号开始传
p=h;
while (h->next!=h){
// 移动两次
p = h->next;
q = h->next->next;
// cout&l...
登录后发布评论
暂无评论,来抢沙发