请写一个双向链表的快速排序函数

#include"double_link.h"

void link_create(node** p)
{
	*p = (node*)malloc(sizeof(node));
	if(*p == NULL)
	{
		perror("malloc");
		return;
	}
	(*p)->len = 0;
	(*p)->next = NULL;
	(*p)->prior = NULL;
}

void link_add(node* p,int x)
{
	node* ptr = (node*)malloc(sizeof(node));
	if(ptr == NULL)
	{
		perror("malloc");
		return;
	}
	ptr->data = x;
	if(p->next == NULL)
	{
		p->next = ptr;
		ptr->prior = p;
		ptr->next = NULL;
	}
	else
	{
		ptr->next = p->next;
		ptr->prior = p;
		p->next->prior = ptr;
		p->next = ptr;
	}
	p->len++;
}

void link_show(node* p)
{
	node* ptr = p;
	while(ptr->next)
	{
		ptr = ptr->next;
		printf("%d ",ptr->data);
	}
	putchar(10);
}

void link_quickly(node* p_frist,node* p_last)
{
	int temp = p_frist->data;
	node* ptr_frist = p_frist;
	node* ptr_last = p_last;
	if(ptr_frist == ptr_last||ptr_frist == NULL || ptr_last == NULL)
	{
		return;
	}
	while(1)
	{
		while(ptr_last->data>temp&&ptr_frist!= ptr_last)
		{
			ptr_last = ptr_last->prior;
		}
		if(ptr_frist == ptr_last)
		{
			break;
		}
		ptr_frist->data = ptr_last->data;
		ptr_frist = ptr_frist->next;

		while(ptr_frist->datanext;
		}
		if(ptr_frist == ptr_last)
		{
			break;
		}
		ptr_last->data = ptr_frist->data;
		ptr_last = ptr_last->prior;

	}
	ptr_frist->data = temp;
	link_quickly(p_frist,ptr_frist->prior);
	link_quickly(ptr_frist->next,p_last);
}

你可能感兴趣的:(链表)