官术网_书友最值得收藏!

Code walkthrough

The following code declares and initializes the forward_list container with some unique values and some duplicate values:

forward_list<int> l = { 10, 10, 20, 30, 45, 45, 50 };

As the forward_list container doesn't support the size() function, we used the distance() function to find the size of the list:

cout << "\nSize of list with duplicates is " << distance( l.begin(), l.end() ) << endl;

The following forward_list<int>::unique() function removes the duplicate integers and retains only the unique values:

l.unique();
主站蜘蛛池模板: 无为县| 克东县| 伊吾县| 进贤县| 开封市| 丹棱县| 曲麻莱县| 聂拉木县| 于田县| 遵义县| 遵义市| 开封县| 根河市| 阿合奇县| 阿克| 吴堡县| 丰都县| 琼海市| 江西省| 望奎县| 海淀区| 定日县| 比如县| 奉化市| 甘孜县| 南昌市| 平江县| 平谷区| 宁安市| 开江县| 涿鹿县| 临朐县| 北碚区| 临潭县| 镶黄旗| 上饶市| 平乐县| 平顺县| 花莲市| 岢岚县| 太仆寺旗|