nth_element 算法注解.pdfVIP

  • 19
  • 0
  • 约5.78千字
  • 约 10页
  • 2016-03-01 发布于山西
  • 举报
nth_element 算法注解

nth_element nth_element nntthh__eelleemmeenntt 算法注解 nth_element 是STL 提供的一个算法,用于找出序列中 的第n大元素。这个算法涉及下面4个辅助函数: • _Nth_element • _Unguarded_partition • _Median • _Med3 下面是我对STL 源代码的注释。 /********************************************* ********************************************** * _Nth_element 使序列中第n大的元素位于第n个位子上,使用 比 较元素。 基本思想: (1) 找到一个包含n的足够小的区间[a,b),使得[a,b) 作为一个大粒度的元素处于序列的有序位置。 (2) 对[a,b)部分进行排序。 nth_element 查找区间的方式体现了二分(折半)查找 的思想。它的核心是 ungarded_partition 算法, ungarded_partition 算法能够找出随机序列的近似的位 置中间值。 ********************************************

文档评论(0)

1亿VIP精品文档

相关文档