Exemple #1
0
void QuickSort(int array[],int start,int end)
{
	int q;
	if(start<end)
	{
		q=Partition(array,start,end);
		QuickSort(array,start,q-1);
		QuickSort(array,q+1,end);
	}
}
void HistoryHeuristic::QSort(ChessMove *source, int low, int high)
{
	int i;
	if (low < high)
	{
		i = Partition(source, low, high);
		QSort(source, low, i - 1);
		QSort(source, i+1, high);
	}
}
Exemple #3
0
void Quick_Sort(int r[], int hs, int ht){
	/*对r[hs]到r[ht]进行快速排序*/
	int i;
	if(hs < ht){
		/*只有1个记录或者无记录时无须排序*/
		i = Partition(r, hs, ht);            /***r[hs] 到 r[ht] 一次划分***/
		Quick_Sort(r, hs, i - 1);           /*递归处理左区间*/
		Quick_Sort(r, i + 1, ht);           /*递归处理右区间*/
	}
}
Exemple #4
0
/*********************************************
函数名:Qsort()
输入:A[]——需要排序的数组
	  Left——数组左边界下标
	  Right——数组右边界下标
输出:无
功能:快速排序
*********************************************/
void Qsort(int A[],int Left,int Right)
{
	int i;
	if(Left<Right)
	{
		i = Partition(A,Left,Right);
		Qsort(A,Left,i-1);
		Qsort(A,i+1,Right);
	}
}
Exemple #5
0
void QuickSortAndCount(int list[],int start,int end,qint64& count,int buffer[])
{
    if(start<end)
    {
        int mid;
        mid=Partition(list,start,end,count,buffer);
        QuickSortAndCount(list,start,mid-1,count,buffer);
        QuickSortAndCount(list,mid+1,end,count,buffer);
    }
}
Exemple #6
0
 // bo10-2.cpp 快速排序的函数
 void QSort(SqList &L,int low,int high)
 { // 对顺序表L中的子序列L.r[low..high]作快速排序。算法10.7
   int pivotloc;
   if(low<high)
   { // 长度大于1
     pivotloc=Partition(L,low,high); // 将L.r[low..high]一分为二
     QSort(L,low,pivotloc-1); // 对低子表递归排序,pivotloc是枢轴位置
     QSort(L,pivotloc+1,high); // 对高子表递归排序
   }
 }
Exemple #7
0
//RandomizeRartition: randomize quick sort 
int RandomizeRartition(int a[], int l, int r)
{
	int i = Random(l, r);

	int temp = a[i];
	a[i] = a[r];
	a[r] = temp;

	return Partition(a, l, r);
}
Exemple #8
0
 /* bo10-2.c 快速排序的函数,包括算法10.7、10.8 */
 void QSort(SqList *L,int low,int high)
 { /* 对顺序表L中的子序列L.r[low..high]作快速排序。算法10.7 */
   int pivotloc;
   if(low<high)
   { /* 长度大于1 */
     pivotloc=Partition(L,low,high); /* 将L.r[low..high]一分为二 */
     QSort(L,low,pivotloc-1); /* 对低子表递归排序,pivotloc是枢轴位置 */
     QSort(L,pivotloc+1,high); /* 对高子表递归排序 */
   }
 }
Exemple #9
0
void QuickSort(T* pArr, size_t Size)
{
	if(Size <= 1 || !pArr)
		return;

	size_t pos = Partition(pArr, Size);

	QuickSort(pArr, pos);
	QuickSort(pArr + pos + 1, Size - pos - 1);
}
Exemple #10
0
void QuickSort(int DataSet[], int Left, int Right)
{
	if (Left < Right)
	{
		int Index = Partition(DataSet, Left, Right);

		QuickSort(DataSet, Left, Index - 1);
		QuickSort(DataSet, Index + 1, Right);
	}
}
Exemple #11
0
void QuickSort(int *array, int low, int high)
{
    if(low < high)
    {
        int pivotloc = Partition(array, low, high);

        QuickSort(array, low, pivotloc-1);
        QuickSort(array,  pivotloc+1, high);
    }
}
Exemple #12
0
void TopK(std::vector<int> &input, int begin, int end, int k) {
    int pivot = Partition(input, begin, end);
    int len = pivot - begin + 1;
    if (len == k)
        return;
    else if (len > k)
        TopK(input, begin, pivot - 1, k);
    else
        TopK(input, pivot + 1, end, k - len);
}
Exemple #13
0
void QuickSort(float List[],int low,int high)
{
	int pivotloc;
	if(low<high)
	{
		pivotloc=Partition(List,low,high);
		QuickSort(List,low,pivotloc-1);
		QuickSort(List,pivotloc+1,high);
	}
}
Exemple #14
0
/*********************************************************************************************************
** Function name: quickSort
** Descriptions:  quicksort algorithm
*********************************************************************************************************/
void LightCom::quickSort(int a,int b, unsigned char *N)
{
    int pivot;
    if(a<b)
    {
        pivot = Partition(a, b, N);
        quickSort(a, pivot-1, N);
        quickSort(pivot+1, b, N);
    }
}
Exemple #15
0
void TXKDTree::QuickSort(float3* points, const int& left, const int& right, const int& x)
{
	if(right>left)
	{
		int pivot = rand_int(left,right);
		int npivot = Partition(points,left,right,x,pivot);
		QuickSort(points,left,npivot-1,x);
		QuickSort(points,npivot+1,right,x);
	}
}
void QuickSort(int* arr,int low,int high){

if(high>low){
int pivot=Partition(arr,low,high);
QuickSort(arr,low,pivot-1);
QuickSort(arr,pivot+1,high);
}


}
void Qsort(SqList *L,int low,int high)//递归形式的快速排序算法
{
	int pivotloc;
    if(low<high)
	{
        pivotloc=Partition(L,low,high);
        Qsort(L,low,pivotloc-1);
        Qsort(L,pivotloc+1,high);
	}
}
Exemple #18
0
void QuickSort(std::vector<int>& nums, int s, int e)
{
	// TODO check parameter valid
	
	if (s < e)
	{
		std::pair<int,int> mid = Partition(nums, s, e);
		QuickSort(nums, s, mid.first-1);
		QuickSort(nums, mid.second+1, e);
	}
}
Exemple #19
0
/* Given:  Buf       Array of char array strings
           Lower     An index into the array.
           Upper     An index into the array.
   Task:   To quicksort the section of the array from index Lower to Upper.
   Return: Buf       The sorted array.
*/
void QuickSort(BufType Buf, int Lower, int Upper)
   {
   int PivotIndex;

   if (Lower < Upper)
      {
      PivotIndex = Partition(Buf, Lower, Upper);
      QuickSort(Buf, Lower, PivotIndex - 1);   // sort left side
      QuickSort(Buf, PivotIndex + 1, Upper);   // sort right side
      }
   }
Exemple #20
0
//分治 
void QuickSort(int src[], int low, int high) {

	if (high < low)
		return;

	int pivot = Partition(src, low, high);
	QuickSort(src, low, pivot - 1);
	QuickSort(src, pivot + 1, high);

	return;
}
Exemple #21
0
void QuickSort(int *a,int low,int high)
{
    int pos;
    if(low < high)
    {
        pos = Partition(a,low,high);
        QuickSort(a,low,pos-1);
        QuickSort(a,pos+1,high); 
    }
    return ;
}
Exemple #22
0
void QSort( SqList* l, int low, int high )
{
	if( low >= high )
	{
		return;
	}
	int pivotloc = 0;
	pivotloc = Partition( l, low, high );
	QSort( l, low, pivotloc-1 );
	QSort( l, pivotloc+1, high );
}
Exemple #23
0
void SortIndices(ULONG *A, long p, long r) 
{
   long q;

   if (p < r)
   {
      q = Partition(A, p, r);
      SortIndices(A, p, q-1);
      SortIndices(A, q+1, r);		
   }
}
Exemple #24
0
void DPQS(Matrix *m,int col, int low, int high)
{
	int lp, rp;
	if(low<high)
	{
		Partition(m,col, low, high, &lp, &rp);
		DPQS(m,col,low,lp-1);
		DPQS(m,col,lp+1,rp-1);
		DPQS(m,col,rp+1,high);
	}
}
Exemple #25
0
void 
Dim::Quicksort( float** d, int left, int right)
{

	if(left < (right- 15)) {
		int split_pt = Partition(d,left, right);
		Quicksort(d, left, split_pt);
		Quicksort(d, split_pt+1, right);
		}
	else SelectionSort(d, left, right);
};
int RandomPartition(int *pnArr, int nLeft, int nRight)
{
    srand(time(NULL));
    int n1 = rand()%(nRight - nLeft + 1) + nLeft;
    int n2 = rand()%(nRight - nLeft + 1) + nLeft;
    int n3 = rand()%(nRight - nLeft + 1) + nLeft;
    int nKey = (n1+n2+n3) / 3;
    Swap(&pnArr[nKey], &pnArr[nRight]);

    return Partition(pnArr, nLeft, nRight);
}
//***********************************************
void QuickSort(int a[], int left, int right)
{
   int pivot;
   if(left >= right)
       return;
   if(left < right)
   {
       pivot = Partition(a, left, right);
       QuickSort(a, left, pivot - 1);
       QuickSort(a, pivot + 1, right);
   }
}
Exemple #28
0
void QuickSort(int left,int right,char * const str)
{
	int pivot;
	if(left<right)
	{
		pivot=Partition(left,right,str);	
		//printf("left=%d\n",left);
		//printf("right=%d\n",right);
		QuickSort(left,pivot-1,str);
		QuickSort(pivot+1,right,str);
	}
}
Exemple #29
0
/* ---------------------------- RECURSIVE QUICKSORT ---------------------- */
void RecQuickSort (Student *hash_table, int *access_table, int low,
		   int high) {
   int pivotpos = 0;
   if (low < high) {
      pivotpos = Partition (hash_table, access_table, low, high);
      /* divide into two sublists */
      RecQuickSort (hash_table, access_table, low, pivotpos - 1);
      /* sort lower sublist */
      RecQuickSort (hash_table, access_table, pivotpos + 1, high);
      /* sort upper sublist */
   }
}
Exemple #30
0
void Sorts::QuickSort(int *intArray, int minSubscript, int maxSubscript)
{
	int i, j;

	if(minSubscript < maxSubscript)
	{
		i = minSubscript; j = maxSubscript;
		Partition(intArray, &i, &j);
		QuickSort(intArray, minSubscript, j);
		QuickSort(intArray, i, maxSubscript);
	}
}