文章

5

粉丝

0

获赞

26

访问

1.2k

头像
遍历链表 题解:
P1405 华中科技大学
发布于2025年3月7日 08:28
阅读数 175

 函数里的struct node * pre=NULL,为什么要赋值NULL,因为我的VScode报错说使用了未初始化值的变量,我就给它赋值NULL了,hhhh

#include <bits/stdc++.h>
using namespace std;
struct node {
    int sum;
    struct node* next;
};
int n;
//排序单链表,这里用的是冒泡排序

struct node* sort(struct node* head) {
    struct node * pre=NULL;
    int tmp;
    for (int i = 1; i <= n; i++) {
        struct node* now = head;
        while (now->next != NULL) {
            if (now->sum > now->next->sum) {
                tmp = now->sum;
                now->sum = now->next->sum;
                now->next->sum = tmp;
    &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发