文章

16

粉丝

134

获赞

0

访问

3.2k

头像
单链表 题解:小伙伴们可以帮我检查一下哪里有问题吗?0%
P1015 贵州大学机试题
发布于2024年3月24日 14:47
阅读数 194

#include<bits/stdc++.h>
using namespace std;
struct Node {
    int Element; // 节点中的元素为整数类型
    struct Node * Next; // 指向下一个节点
};

struct Node* create(int a[10]) {
    struct Node* head = (struct Node *)malloc(sizeof(Node));//建立头节点
    head->Next = NULL;//头结点指向空;
    struct Node* p = head;//这个结点用来移动
    for(int i = 0; i < 5; i++) {
        struct Node *now = (struct Node*)malloc(sizeof(Node));
        now->Element = a[i];
        now->Next=NULL;
        p->Next = now;
        p=now;
    }
    return head;
}

void Sort(struct Node*head) {
    for(int i = 0; i < 5; i++) {
        struct Node *p;
        p = head;
        while(p->Next != NULL) {
         ...

登录查看完整内容


登录后发布评论

2 条评论
snake
2024年3月24日 17:58

你这个头结点创建了一个空间,但是却没有存储值,是从head的next节点开始存储的,那么输出的时候也应该从head->next开始输出。

赞(0)

为欢几何 : 回复 snake: 谢谢你

2024年3月28日 09:12