请问这个排序错在哪里
最近编了一道用快速排序法建立双向链表,有11处错误,但限于C的水平未能发现,请高手指教程序如下;
#define NULL 0
typedef struct Node
{
int key;
int Data;
struct Node *Pre;
struct Node *Next;
} Node,*Linklist;
main()
{
Linklist Head,Tail;
int Lenth;
Head=Tail=(Linklist)malloc(sizeof(Node));
printf("How many do you want?/n");
scanf("%d",&Lenth);
CreateLinklist(Lenth,Tail,Head);
QuickSort(Head,Tail);
PrintLinklist(Head);
}
void CreateLinklist(int n,Linklist Tail,Linklist Head)
{
Linklist L,p,H;
int i=0;
H=L=p=(Linklist)malloc(sizeof(Node));
H->Pre=NULL;
while(n!=NULL)
{
scanf("%d",&n);
p->key=i++;
p->Data=n;
L->Next=p;
p->Pre=L;
}
p->Next=NULL;
Tail=p;
Head=H;
}
void NodePreMove(Linklist *q)
{
Linklist T=(Linklist)malloc(sizeof(Node));
T=q->Pre;
free(q);
q=T;
}
void NodeNextMove(Linklist *p)
{
Linklist T=(Linklist)malloc(sizeof(Node));
T=p->Next;
free(p);
p=T;
}
void Partition(Linklist *low,Linklist *high)
{
int T;
Linklist p=(Linklist)malloc(sizeof(Node));
Linklist q=(Linklist)malloc(sizeof(Node));
Linklist Temp=(Linklist)malloc(sizeof(Node));
Linklist Pivotkey=(Linklist)malloc(sizeof(Node));
p=Temp=Pivotkey=low;
q=high;
while (p < q)
{
while (p->Data < q->Data && q->Data >= Pivotkey->Data) NodePreMove(q);
T=q->Data;
q->Data=p->Data;
p->Data=T;
while (p->Data < q->Data && p->Data <= Pivotkey->Data) NodeNextMove(p);
T=q->Data;
q->Data=p->Data;
p->Data=T;
}
p = Temp;
return p;
}
void QuickSort(Linklist *low,Linklist *high)
{
if (low < high)
{
Linklist pivotloc = Partition(low, high);
qSort(low,NodePreMove(pivotloc));
qSort(NodeNextMove(pivotloc), high);
}
}
void PrintLinklist(Linklist *Head)
{
Linklist Temp;
printf("The Linklist: ");
do
{
printf("%d ",p->data);
Temp=p->Next;
free(p);
p=Temp;
}
while(p!=NULL);
}