文章
61
粉丝
137
获赞
18
访问
38.4k
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int number;
struct node* next;
}LiNode, *LiList;
int main(){
int n;
cin >> n;
LiList L = (LiList) malloc(sizeof(LiNode));
L->number = 1;
L->next = L; //不带头节点的循环单链表
LiNode *rear = L; //尾指针
LiNode* p;
//插入循环单链表
for(int i = 2; i <= n; i++){
p = (LiNode*) malloc(sizeof(LiNode));
p->number = i;
rear->next = p;
p->next = L;
rear = p;
}
/*
p = L;
cout << p->number << endl;
while(p->next != L){
p = p->next;
cout << p->number << endl;
}
*/
//开始击鼓传花
p = rear;
LiNode *q;
for(int i = 0; i < n-1; i++){
p = p->next->next;
q = p->next;
p->next = q->next;
free(q);
}
cout << p->number;
ret...
登录后发布评论
暂无评论,来抢沙发