`
yuanlanjun
  • 浏览: 1184731 次
文章分类
社区版块
存档分类
最新评论

merge,inplace_merge

 
阅读更多

直接代码如下

//merge
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
bool fanxu(int a,int b){
	return a>b;
}
int main(){
	int a[]={1,5,3,9,7};
	int b[]={4,2,6,10,8};
	vector<int>v(a,a+5);
	vector<int>vv(b,b+5);
	sort(v.begin(),v.end());
	sort(vv.begin(),vv.end());
	merge(v.begin(),v.end(),vv.begin(),vv.end(),ostream_iterator<int>(cout," "));
	cout<<endl;
	
	for(vector<int>::iterator itera=v.begin();itera!=v.end();++itera){//还有元素,说明跟list的成员函数不一样list的merge是会破坏源区间的
		cout<<*itera<<" ";
	}
	cout<<endl;

	sort(v.begin(),v.end(),fanxu);//按照从大到小排序
	sort(vv.begin(),vv.end(),fanxu);
	merge(v.begin(),v.end(),vv.begin(),vv.end(),ostream_iterator<int>(cout," "),fanxu);//按照从大到小排序
	cout<<endl;
	system("pause");
	return 0;
}

//inplace_merge
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int a[]={1,2,3,4,5,6,7,1,2,3,4,5,6,7,8,9,10};
	vector<int>v(a,a+17);
	vector<int>::iterator itera=find(v.begin(),v.end(),7);
	
	++itera;//是7的下一个
	inplace_merge(v.begin(),itera,v.end());//这里可以用partial_sort和merge来实现
	for(vector<int>::iterator iter=v.begin();iter!=v.end();++iter){
		cout<<*iter<<" ";
	}
	cout<<endl;
	system("pause");
	return 0;	
}



分享到:
评论

相关推荐

    mem.rar_Same Same

    Place all memblock_regions in the same node and merge contiguous memblock_regions.

    Araxis Merge Professional 2012.4162 (x86/x64).part1

    The in-place editor with unlimited undo enables complete control over the merged file as you create it. The file comparison display dynamically updates as the merge progresses. Merge shows detailed ...

    Araxis Merge Professional 2012.4162 (x86/x64).part2

    The in-place editor with unlimited undo enables complete control over the merged file as you create it. The file comparison display dynamically updates as the merge progresses. Merge shows detailed ...

    stl详解 包括各种实例代码

    15. merge / inplace_merge 35 16. includes 36 17. set_union, set_intersection, set_difference, set_symmetric_diffrece 36 18. next_permutation / prev_permutation 36 19. power 37 20. heap operations 38 ...

    STL 源码剖析(侯捷先生译著)

    6.7.11 inplace_merge(应用于有序区间) 403 6.7.12 nth_element 409 6.7.13 merge sort 411 第7章 仿函数(functor,另名 函数对象function objects) 413 7.1 仿函数(functor)概观 413 7.2 可配接...

    UG6.0快捷键大全

    SYNONYMS locate, place, transform, orient HINT This command is available in history modeling mode. HELP DSN_feature_edit BITMAP movefeature ACTIONS STANDARD !HIDDEN BUTTON UG_MODELING_EDIT_...

    leetcode2sumc-interview:数据结构与算法面试题及解答

    4:库inplace_merge 合并排序 合并两个已排序的数组。 快速排序 使用快速排序算法对数组进行排序。 珠排序 使用珠排序算法对数组进行排序。 字符串 字谜 确定两个字符串是否是字谜 版本 1:排序 版本 2:字符映射 ...

    C++ STL 开发技术导引(第6章)

    23.10 内部归并inplace_merge 368 23.11 稳定排序stable_sort 376 23.12 是否排序is_sorted 383 23.13 第n个元素nth_element 384 23.14 下确界lower_bound 386 23.15 上确界upper_bound 388 23.16 等价...

    C++ STL开发技术导引(第5章)

    23.10 内部归并inplace_merge 368 23.11 稳定排序stable_sort 376 23.12 是否排序is_sorted 383 23.13 第n个元素nth_element 384 23.14 下确界lower_bound 386 23.15 上确界upper_bound 388 23.16 等价...

    C++ STL开发技术导引(第3章)

    23.10 内部归并inplace_merge 368 23.11 稳定排序stable_sort 376 23.12 是否排序is_sorted 383 23.13 第n个元素nth_element 384 23.14 下确界lower_bound 386 23.15 上确界upper_bound 388 23.16 等价...

    -C++参考大全(第四版) (2010 年度畅销榜

    34.17 inplace_merge 34.18 iter_swap 34.19 lexicographical_compare 34.20 lower_bound 34.21 make_heap 34.22 max 34.23 max_element 34.24 merge 34.25 min 34.26 min_element 34.27 mismatch 34.28 next_...

    STL源码剖析.pdg

    6.7.11 inplace_merge(应用于有序区间) 403 6.7.12 nth_element 409 6.7.13 merge sort 411 第7章 仿函数(functor,另名 函数对象function objects) 413 7.1 仿函数(functor)概观 413 7.2 可配接...

    微软内部资料-SQL性能优化5

    The data is stored in one place and the index is stored in another. Pointers indicate the storage location of the indexed items in the underlying table. In a nonclustered index, the leaf level ...

    C++大学教程,一本适合初学者的入门教材(part2)

    20.5.9 inplace_merge、 unique—copy和reverse—copy 20.5.10 集合操作 20.5.11 1ower—bound、 upper—bound和equal_range 20.5.12 堆排序 20.5.13 min和max 20.5.14 本章未介绍的算法 20.6 bitset类...

    C++大学教程,一本适合初学者的入门教材(part1)

    20.5.9 inplace_merge、 unique—copy和reverse—copy 20.5.10 集合操作 20.5.11 1ower—bound、 upper—bound和equal_range 20.5.12 堆排序 20.5.13 min和max 20.5.14 本章未介绍的算法 20.6 bitset类...

    Qwinff_0.1.9中文版(跨平台媒体转换器qt)

    - (Packaging) (Windows) Place Qt translation files in "translations" folder - (Packaging) (Windows) QWinFF now depends on QtNetwork4.dll (for update checker). - (Packaging) (Windows) merge "ffmpeg...

    lrucacheleetcode-geekbang-algorithms:geekbang-算法

    要求:对nums1进行inplace处理,并且已经为nums1开辟好了(n+m)大小的空间,默认后面用0补齐,可直接处理。 细节: 从数组前面开始,会出现元素被覆盖的可能,即后面的输入被前面的结果覆盖;需要另外开一个数组保存...

    SQLPrompt_7.4.0.471

    Fix problem with Add/remove AS keyword in MERGE statements Fix window functions and GROUP BY suggestions (forum) SQL Prompt now always escapes an alias if it's a keyword (forum) Columns are no longer ...

    SQLPrompt_7.4.1.603

    Fix problem with Add/remove AS keyword in MERGE statements Fix window functions and GROUP BY suggestions SQL Prompt now always escapes an alias if it's a keyword Columns are no longer qualified inside...

    Introduction to Algorithms(算法导论)

    Chapter 1 is an overview of algorithms and their place in modern computing systems. This chapter defines what an algorithm is and lists some examples. It also makes a case that algorithms are a ...

Global site tag (gtag.js) - Google Analytics