#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <iomanip>
#include<iostream>
using namespace std;
struct ListNode
{
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
int main()
{
ListNode a(1);
ListNode b(2);
ListNode c(3);
ListNode d(4);
ListNode e(5);
ListNode f(6);
a.next = &b;
b.next = &c;
c.next = &d;
d.next = &e;
e.next = &f;
f.next=&a;
ListNode* head = &a;
for(int i=1; i<6; i++)
{
for(int j=1; j<4; j++)
head=head->next;
head->next=head->next->next;
head=head->next;
}
cout<<head->val<<endl;
}
C++循环链表实现约瑟夫问题
最新推荐文章于 2024-04-21 17:11:32 发布