10 11 3 5 27 9 12 43 16 84 22
22 84 16 43 12 9 27 5 3 11
贴一下代码吧:
#include <stdio.h>
#include <malloc.h>
typedef struct Node
{
    int data;
    struct Node* next;
}Lnode;
Lnode*create(int n)
{
    Lnode *head,*p;
    int i;
    head=(Lnode*)malloc(sizeof(Lnode));   //这句话和下一句一定不要写反了,不然老会有错误
    head->next=NULL;
    for(i=1;i<=n;i++)
    {
        p = (Lnode*)malloc(sizeof(Lnode));
        scanf("%d",&p->data);
        /*head->next = p;
        tail=p;
        tail->next = NULL;
        */
        p->next=head->next;
        head->next=p;
    }
    return head;
}
int main()
{
    int n;
    Lnode *head,*q;
    scanf("%d",&n);
    head=create(n);
    q=head;
    while(q->next!=NULL)
    {
        printf("%d ",q->next->data);
        q=q->next;
    }
    printf("\n");
    return 0;
}
一定要注意逆序的时候是怎么样插入的。本文出自 “我的算法笔记” 博客,谢绝转载!
原文:http://liu168ad.blog.51cto.com/7511123/1383605