当前位置: 首页>>代码示例>>C++>>正文


C++ siftDown函数代码示例

本文整理汇总了C++中siftDown函数的典型用法代码示例。如果您正苦于以下问题:C++ siftDown函数的具体用法?C++ siftDown怎么用?C++ siftDown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了siftDown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: int

node *buildHeap(struct stack *s, int(*lt)(int, int))
{
    node *g = top(s);
    treeNode *b = g->treeN->parent;
    while(g->treeN->parent != NULL)
    {
        b = g->treeN->parent;
        if(b->right != NULL) //it's a right child
        {
            siftDown(b, lt);
            if(g->next->next != NULL)
            {
                g = g->next->next;
            }
        }
        else    //it's a left child
        {
            siftDown(b, lt);
            if(g->next != NULL)
            {
                g = g->next;
            }
        }
    }
    return g;
}
开发者ID:JPohl41,项目名称:CS201,代码行数:26,代码来源:heap.c

示例2: hsort64

void hsort64(U128T records[], size_t count)
{
	int64_t start, end;
	U128T temp;

	status = 0;
	puts("Heapifying records");
	for (start=count/2-1; start>=0; start--) {
		if (bailout)
			exit(1);
		siftDown(records, start, count);
		status = count - 2*start;
	}

	status = 0;
	puts("Sorting records");
	for (end=count-1; end>0; end--) {
		if (bailout)
			exit(1);
		temp = records[end];
		records[end] = records[0];
		records[0] = temp;
		siftDown(records, 0, end);
		status = count - end + 1;
	}
}
开发者ID:fulldecent,项目名称:pawn-bfs,代码行数:26,代码来源:hsort.c

示例3: heapSort

void heapSort(int *a, int count) {
        int start, end;
        for (start = (count-2)/2; start >=0; start--) {
                siftDown( a, start, count);
        }//for

        for (end=count-1; end > 0; end--) {
                SWAP(a[end],a[0]);
                siftDown(a, 0, end);
        }//for
}//heapSort
开发者ID:cmiller356,项目名称:modifiedQuickSort,代码行数:11,代码来源:subarrayheapsort.c

示例4: heapSort

void heapSort(void* buf, size_t size, size_t total, int (*compare)(void const* a, void const* b)) {
	int start, end;

	for(start = (total - 2) / 2; start >= 0; start--) {
		siftDown(buf, size, start, total, compare);
	}

	for(end = total - 1; end > 0; end--) {
		exch(buf, end, 0, size);
		siftDown(buf, size, 0, end, compare);
	}
}
开发者ID:leaderwing,项目名称:test_repo,代码行数:12,代码来源:heap_sort.c

示例5: heapSortHelper

void heapSortHelper (int* a, int first, int last)
{
    for (int i = last / 2; i >= first; i--)
    {
        siftDown(a, i, last);
    }
    for (int i = last; i > first; i--)
    {
        Sort::swap (a[i], a[first]);
        siftDown (a, first, i - 1);
    }
}
开发者ID:kcomputer,项目名称:homework,代码行数:12,代码来源:heapSort.cpp

示例6: heap_sort

void heap_sort(int a[], int n){
	int i, temp;

	for (i = (n / 2)-1; i >= 0; i--)
		siftDown(a, i, n);

	for (i = n-1; i >= 1; i--){
		temp = a[0];
		a[0] = a[i];
		a[i] = temp;
		siftDown(a, 0, i-1);
	}
}
开发者ID:CCJY,项目名称:coliru,代码行数:13,代码来源:main.cpp

示例7: internal_heapsort

void internal_heapsort(int *a, int count)
{
  int start, end;

  /* heapify */
  for (start = (count - 2) / 2; start >= 0; start--) {
    siftDown(a, start, count);
  }

  for (end = count - 1; end > 0; end--) {
    SWAP(a[end], a[0]);
    siftDown(a, 0, end);
  }
}
开发者ID:jbcarleton,项目名称:seacas,代码行数:14,代码来源:tec.c

示例8: heapSort

void heapSort(LONG_T* keys, LONG_T* auxKey1, WEIGHT_T* auxKey2, LONG_T n)
{
	LONG_T i;

	for (i = (n/2)-1; i >= 0; i--)
		siftDown(keys, auxKey1, auxKey2, i, n);

	for (i = n-1; i >= 1; i--) {
		swapL(&keys[0], &keys[i]);
                swapL(&auxKey1[0], &auxKey1[i]);
                swapW(&auxKey2[0], &auxKey2[i]);
		siftDown(keys, auxKey1, auxKey2, 0, i-1);
	}

}
开发者ID:aritraghosh,项目名称:Incremental-BC,代码行数:15,代码来源:utils.c

示例9: HeapSortAsc

void HeapSortAsc( int *I ) /* sort array I in ascending order using heap sort algorithm */ 
{
	int i, tmp;
	//Make a heap!
	//Heapify
	for (i = (size-2)/2; i >=0; i--)
		siftDown(I,i,size);
	for (i = size-1; i >= 1; i--){
		tmp = I[0];
		I[0] = I[i];
		I[i] = tmp;
		siftDown(I,0,i);
	}
	return;
}
开发者ID:jared-hess,项目名称:CS460,代码行数:15,代码来源:prog8.c

示例10: heapsort

void heapsort(long * numbers, long n, int isort)
{
  long i, temp;
 
  for (i = (n / 2); i >= 0; i--)
    siftDown(numbers, i, n - 1,isort);
 
  for (i = n-1; i >= 1; i--)
  {
    temp = numbers[0];
    numbers[0] = numbers[i];
    numbers[i] = temp;
    siftDown(numbers, 0, i-1,isort);
  }
}
开发者ID:dsiska,项目名称:grad511,代码行数:15,代码来源:hw7.c

示例11: heapify

void heapify(RandomAccessIterator first, RandomAccessIterator last) {
    RandomAccessIterator start = first + (last - first)/2 - 1;
    while (start >= first) {
        siftDown(first, start, last-1);
        --start;
    }
}
开发者ID:jureslak,项目名称:Tweaksort,代码行数:7,代码来源:h.hpp

示例12: siftDown

void siftDown(int numbers[], int root, int bottom) 
{
	int maxChild = root * 2 + 1;	
	
	// Find the biggest child
	if(maxChild < bottom) 
	{
		int otherChild = maxChild + 1;
		// Reversed for stability
		maxChild = (numbers[otherChild] > numbers[maxChild])?otherChild:maxChild;
	} 
	else 
	{
		// Don't overflow
		if(maxChild > bottom) 
			return;
	}	
	
	// If we have the correct ordering, we are done.
	if(numbers[root] >= numbers[maxChild])
		return;	
	
	// Swap
	int temp = numbers[root];
	numbers[root] = numbers[maxChild];
	numbers[maxChild] = temp;	
	
	// Tail queue recursion. Will be compiled as a loop with correct compiler switches.
	siftDown(numbers, maxChild, bottom);
}
开发者ID:noquarter12,项目名称:codeCave,代码行数:30,代码来源:heapSort.c

示例13: heapify

void heapify( TreeNode ** node){
	TreeNode * p = *node;
	while( p != NULL){
		siftDown( &p);
		p=p->getPrev();
	}
}
开发者ID:sourimd,项目名称:Sorting,代码行数:7,代码来源:main.cpp

示例14: heapSort

void heapSort( TreeNode ** rt, TreeNode ** lt, std::vector<int> & vec){
	TreeNode * temp = *lt;
	TreeNode * tempParent;
	//TreeNode * temp2;

	while( temp != NULL){
		if( temp == *rt){
			vec.push_back( (*rt)->getValue() );
			break;
		}
		vec.push_back( (*rt)->getValue() );
		(*rt)->setValue( temp->getValue() );
		tempParent = temp->getParent();
		if( tempParent->getRight() == temp){
			tempParent->setRight(NULL);
		}
		if( tempParent->getLeft() == temp){
			tempParent->setLeft(NULL);
		}
		temp = temp->getPrev();
		if( temp!=NULL){
			temp->setNext( NULL);
		}
		
		//delete temp1;
		//temp1 = NULL;
		siftDown( rt);
	}
}
开发者ID:sourimd,项目名称:Sorting,代码行数:29,代码来源:main.cpp

示例15: siftDown

    void siftDown(T (&a)[N], int index) {//max-heap
      while (2*index + 1 < N) {
        int l = 2*index + 1;
        if (l + 1 < N && a[l+1] < a[l]) {
          ++l;
        }
        if (a[l] < a[index]) {
          std::swap(a[l], a[index]);
        }
        index = l;
      }
#if INTRO_ALGRO
      int l = 2*index; //index start from 1
      int r = 2*index + 1;
      int largest = -1;
      if (l <= N && a[l] > a[index]) {
        largest = l; 
      }
      else {
        largest = index;
      }
      if (r <= N && a[r] > a[largest]) {
        largest = r;
      }
      if (largest != index) {
        std::swap(a[largest], a[index]);
        siftDown(a, largest);
    }
#endif
  }
开发者ID:kayw,项目名称:CareerInterview,代码行数:30,代码来源:heapsort.hpp


注:本文中的siftDown函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。