文章

16

粉丝

134

获赞

0

访问

3.4k

头像
击鼓传花 题解:循环链表,AC
P1018 贵州大学机试题
发布于2024年3月24日 15:42
阅读数 210

#include<bits/stdc++.h>
using namespace std;
struct node {
    int n;
    struct node *next;
};
//创建循环链表
struct node * create(int n) {
    struct node* head = (struct node*)malloc(sizeof(struct node));
    head->next = NULL;
    struct node * p = head;
    for(int i = 1; i <= n; i++) {
        struct node* now = (struct node*)malloc(sizeof(struct node));
        if(i == 1) {
            head = now;
            p = now;
        }
        now->n = i;
        now->next = head;
        p->next = now;
        p = now;
    }
    return head;
}
void print(struct node*head) {
    struct node*p = head->next;
    int i = 1;
    while(p-&g...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发