为什么这个插入排序刷了一屏-1


#include <stdio.h>
#include <stdlib.h>
#include<math.h>
typedef   int data_type ;
typedef struct item{

    data_type x;
    int key;
    struct item *next;

}item_type;
item_type *p,*p0,*r,*r0,*j,*front,*rear;
item_type *sort(item_type *base)
{


    p=base;
    while(p!=NULL)
    {
        r=base;
        while((r->x<p->x)&&(r!=p))
        {
            r0=r;
            r=r->next;


        }
        if(r!=p)
        {
            j=p;
            p0->next=p->next;
            p=p0;
            if(r==base)
            {
                base=j;
                j->next=base;

            }
            else{
            r0->next=j;
            j->next=r;}


        }
        p0=p;
        p=p->next;



    }
    return base;



}
int main(void){
    int n;
    scanf("%d",&n);
    p=(item_type*)malloc(sizeof(item_type));
    p->x=n;
    p->next=front;
    front=p;
    while(p->x!=-1)
    {
        p0=p;
         p=(item_type*)malloc(sizeof(item_type));
        scanf("%d",&n);
         p->x=n;

       p0->next=p;

    }

    front=sort(front);
    p=front;
    while(p!=NULL)
    {
        printf("%d",p->x);
        p0=p;
        p=p->next;
    }
    return 0;
 }

想知道哪里写错了呢,以及原因
谢谢!