文章

3

粉丝

414

获赞

5

访问

7.8k

头像
循环链表解决
P1018 贵州大学机试题
发布于2023年3月23日 20:56
阅读数 3.0k

#include "bits/stdc++.h"

#include

#include

#include

 

using namespace std;

#define NUM 3

 

struct Node {

    int id;

    struct Node *next;

    Node(int x) : id(x), next(NULL){};

};

 

struct Node* createLink(int n){

    struct Node *cur, *pre = NULL;

    struct Node *head = new Node(1);

    cur = head;

    for (int i = 2; i <= n; i++){

        struct Node *temp = new Node(i);

        cur->next = temp;

        cur = cur->next;

        pre = temp;

    }

    pre->next = head;

    return head;

}

 

int playGame(struct Node *head){

    struct Node *startNode = head; // 下一次开始传花的人

    struct Node *cur; // 接到花的人

    struct Node *pre; // 接到花的人的前一个人

&n...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发