代码在vc++6。
0下编译通过
#include
#include
struct point
{
int data;
point *next, *last;
} *head = NULL, *tail = NULL;
//快排
void QuickSort(struct point *head, struct point *tail)
{
bool op = true;//标识选定的基是在前还是在后
int t;
struct point *p = head, *q = tail, *tt;
while (p != q)
{
if (op)
{
if (p->data data)
q = q->last;
else
{
op = false;
t = p->data;
p->data = q->data;
q->data = t;
tt = p;
p = q;
q = tt;
}
}
else
{
if (q->data data)
q = q->next;
else
{
op = true;
t = p->data;
p->data = q->data;
q->data = t;
tt = p;
p = q;
q = tt;
}
}
}
if (head != p)
QuickSort(head, p->last);
if (tail != p)
QuickSort(p->next, tail);
}
void main()
{
int t;
struct point *p;
scanf("%d", &t);
if (t != 0)
{
head = (struct point *)malloc(sizeof(struct point));
head->data = t;
head->last = NULL;
head->next = NULL;
tail = head;
scanf("%d", &t);
while (t != 0)
{
p = (struct point *)malloc(sizeof(struct point));
p->data = t;
p->last = tail;
p->next = NULL;
tail->next = p;
tail = p;
scanf("%d", &t);
}
}
QuickSort(head, tail);
for (p = head; p != NULL; p = p->next)
printf(" %d ", p->data);
printf("\n");
}。
全部