#include
#include
typedef struct pan
{
int data;
struct pan *next,*prior;
} Panda;
void Input(Panda *head,int N)
{
Panda *p=head;
while(N--)
{
Panda *pnew=new Panda;
scanf("%d",&pnew->data);
p->next=pnew;
pnew->prior=p;
pnew->next=head;
head->prior=pnew;
p=pnew;
}
return ;
}
void QuickSort(Panda *head,int i,int j,Panda *low,Panda *high)
{
if(i>=j) return ;
int pl=i,pr=j;
Panda *ql=low,*qr=high;
Panda *cub=new Panda;
cub->data=low->data;
while(i<j)
{
while(i<j&&high->data>=cub->data) high=high->prior,j--;
low->data=high->data;
while(i<j&&low->data<=cub->data) low=low->next,i++;
high->data=low->data;
}
low->data=cub->data;
QuickSort(head,pl,i-1,ql,low->prior);
QuickSort(head,i+1,pr,low->next,qr);
return ;
}
void Output(Panda *head)
{
Panda *p=head->next;
while(p!=head)
{
printf("%d\n",p->data);
p=p->next;
}
return ;
}
int main()
{
Panda *head=new Panda;
head->next=head->prior=head;
int N=10;
Input(head,N);
QuickSort(head,1,N,head->next,head->prior);
Output(head);
return 0;
}
/**************************************************************
Language: C++
Result: Accepted
Time:0 ms
Memory:1028 kb
****************************************************************/
2(4).选择排序_快排(双向循环链表)
点赞
收藏