单链表逆置

#include 
#include 

typedef struct Node
{
    int data;
    struct Node *next;
}*rlink;
rlink create()
{
    rlink s=(rlink)malloc(sizeof(struct Node));
    if(s==NULL)
        return NULL;
    else
        s->data=0;
        s->next=NULL;
        return s;
}
rlink insert_rear(rlink L,int element)
{
    rlink s= create();
    s->data=element;
    if(L==NULL)
    {
        L=s;
    }
    else{
        rlink p=L;
        while(p->next!=NULL)
        {
            p=p->next;
        }
        p->next=s;
    }
    return L;
}
rlink ni(rlink L)
{
    if(L==NULL)
    {
        return NULL;
    }
    else if(L->next==NULL)
    {
        return L;
    } else
    {
        rlink p=ni(L->next);
        L->next->next=L;
        L->next=NULL;
        return p;
    }
}
void output(rlink L)
{
    if(L==NULL)
    {
        puts("link is NULL");
        return;
    }
        rlink p=L;
        while (p!=NULL)
        {
            printf("%d\t",p->data);
            p=p->next;
        }
        puts("");
}
int main() {
   rlink L=NULL;
   int n,element;
   printf("please input n:");
    scanf("%d",&n);
    for(int i=0;i

你可能感兴趣的:(算法,数据结构)