容器篇 set容器(下)

2021-10-11 21:32:17 字數 1030 閱讀 9357

#include

#include

#include

using

namespace std;

void

printset

(set<

int>

& s)

/*set容器中的元素不能是重複的,保持唯一性!*/

/*multiset容器中是允許出現重複元素的!*/

/*insert:*/

void

test01()

; s1.

insert

(arr, arr +

sizeof

(arr)

/sizeof

(int))

;printset

(s1)

; cout <<

"-------s2--------"

<< endl;

set<

int> s2;

s2.insert

(s1.

begin()

, s1.

end())

;printset

(s2);}

//自定義型別的插入:set容器在插入實現了自動排序功能,

//但是對於自定義型別來說,必須指定排序的方式,否則是不行的!

//以下是在類之中過載了《運算子,所以實現了自定義型別的排序功能 !

//我們之前:通過自定義仿函式實現了自定義型別的排序!

class

student

~student()

bool

operator

<

(const student& stu)

const

void

show()

const

private

:int num;

string name;};

void

test02()

intmain()

set容器 map容器

簡介 本質 set和multiset區別 構造 賦值 include void printset set int s cout endl 構造和賦值 void test01 intmain 總結 函式原型 include void printset set int s cout endl 大小 vo...

C STL容器篇set和multiset

set和multiset和特點 通常底層由紅黑樹實做而成,會將放入的元素自動排序,所以其優點為搜尋元素時具有良好的效能,使用時需包含標頭檔案set,開啟std命名空間。set和multiset不同之處 set不能放相同的元素,重複放入相同的元素只會放入乙個,multiset可以放入相同的元素。set...

set容器總結

1.關於set c stl 之所以得到廣泛的讚譽,也被很多人使用,不只是提供了像vector,string,list等方便的容器,更重要的是stl封裝了許多複雜的資料結構演算法和大量常用資料結構操作。vector封裝陣列,list封裝了鍊錶,map和set封裝了二叉樹等,在封裝這些資料結構的時候,s...