• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ siftDown函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: siftDown

void siftDown(treeNode *front, int(*lt)(int, int))
{
    treeNode *left = front->left;
    treeNode *right = front->right;
    treeNode *smallestOrLargest = front;
    int indicator = 0;  //swap indicator
    if(front->left != NULL && lt(left->value, smallestOrLargest->value))    //if there's a left child and it's value compares with the other
    {
        smallestOrLargest = left;
        indicator = 1;
    }
    if(front->right != NULL && lt(right->value, smallestOrLargest->value))  //if there's a right child and it's value compares with the other
    {
        smallestOrLargest = right;
        indicator = 2;
    }
    if(indicator == 0)  //no swap was made
    {
        return;
    }
    if(smallestOrLargest->value != front->value)    //if the original smallest or largest moved to a new node, swap and recursively call siftDown
    {
        swap(&smallestOrLargest->value, &front->value); 
        siftDown(smallestOrLargest, lt);
    }
}
开发者ID:JPohl41,项目名称:CS201,代码行数:26,代码来源:heap.c


示例17: buildHeap

void buildHeap(int *a, int n)
{
    for(int i=(n-2)/2; i>=0; i--)
    {
        siftDown(a, n, i);
    }
}
开发者ID:proactivezjuer,项目名称:source_backup,代码行数:7,代码来源:heap.cpp


示例18: heapsort

void heapsort(int arr[], int array_size)
{
  int i, temp;
  for (i = (array_size / 2); i >= 0; i--)
    siftDown(arr, i, array_size - 1);			//Heapify

  for (i = array_size-1; i >= 1; i--)
  {
    // Swap
    temp = arr[0];
    arr[0] = arr[i];
    arr[i] = temp;

    siftDown(arr, 0, i-1);
  }
}
开发者ID:kodingmach12,项目名称:MyCodes,代码行数:16,代码来源:heapsort.c


示例19: deleteMin

void HeapOrderedTree :: deleteMin(){
  if( !empty() ){
    swap( heap[1], heap[tail_index] );
    tail_index--;
    siftDown();
  }
}
开发者ID:EricRobertBrewer,项目名称:SonomaState,代码行数:7,代码来源:HeapOrderedTree.cpp


示例20: drainHeap

 void drainHeap() {
     size_t const count = a.size(buf);
     for (ssize_t next = count; next > 1; next--) {
         a.swap(buf, next, 1);
         siftDown(1, next - 1);
     }
 }
开发者ID:tarsa,项目名称:SortAlgoBox,代码行数:7,代码来源:sortheapbinaryonebasedvarianta.hpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sig函数代码示例发布时间:2022-05-30
下一篇:
C++ sieve函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap