为什么我的链表输出来是逆序的/(ㄒoㄒ)/~~


#include<iostream>
#include<malloc.h>
using namespace std;
typedef struct Node
{
    int data;
    struct Node *next;
}Node;
int a[10];
Node *creat(int a[], int n)
{
    Node *s = NULL;
    Node *first = (Node *)malloc(sizeof(Node));
    first -> next = NULL;
    for(int i = 0; i < n; i ++)
    {
        s = (Node *)malloc(sizeof(Node));
        s -> data = a[i];
        s -> next = first -> next;
        first -> next= s;
    }
    return first;
}

void PrintList(Node *first)
{
    Node *p = first -> next;
    while(p != NULL)
    {
        cout << p->data << " ";
        p = p -> next;
    }
}

int main()
{
    for(int i = 0; i < 10; i ++)
    {
        cin >> a[i];
    }
    int n = 10;
    Node *first = creat(a, n);
    PrintList(first);
    return 0;
}

因为你用的是头插法。

你用头插法,自然就是倒过来的。新加入的数据你插入到前面,不就是反的么
考虑用尾插法吧