Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

快速排序算法中,和看到的c的实现不一样 #68

Open
niezuxue opened this issue Sep 26, 2019 · 0 comments
Open

快速排序算法中,和看到的c的实现不一样 #68

niezuxue opened this issue Sep 26, 2019 · 0 comments

Comments

@niezuxue
Copy link

niezuxue commented Sep 26, 2019

在一本算法结构的书中,介绍的快速排序,每一趟排序都会去交换。
但这里的好像只是找到了比基准值大的和小的两个数组,然后最后再去合并。
书上的c的实现:
`int Quick(List R, int low, int high)
{
x=R[low];

while(low<high)
{
	while((low<high) && R[high].key >= x.key) 
	{
		high --;
	}
	R[low] = R[high];

	while(low<high && R[low].key <= x.key)
	{
		low++;
	}
	R[high] = R[low];
}

R[low] = x;
return low;

}

void QuickSort(List R, int low, int high)
{
if (low < high)
{
temp = Quick(R, low, high);
QuickSort(R, low, temp - 1);
QuickSort(R, temp + 1, high);
}
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant