文章

17

粉丝

0

获赞

5

访问

1.3k

头像
单链表 题解:只为锻炼手搓单链表和相关功能
P1015 贵州大学机试题
发布于2025年5月3日 17:49
阅读数 92

#include<bits/stdc++.h>
using namespace std;

struct Node{
    int Element;
    struct Node *Next;
};

Node *create(vector<int> num){
    Node *head=nullptr,*q=nullptr;//声明同时赋值,防止出现野指针
    for(int i=0;i<5;i++){//头插或尾插无所谓,如果是先排序再插入链表那就选尾插
        Node *p=(Node *)malloc(sizeof(Node));
        p->Element=num[i];
        p->Next=nullptr;
        if(head==nullptr){
            head=p;
        }
        else{
            q->Next=p;
        }
        q=p;
    }
    return head;
};

void sort(Node *head){//冒泡排序
    ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发