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

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();
主站蜘蛛池模板: 洞口县| 旌德县| 卢龙县| 扶风县| 郧西县| 息烽县| 开远市| 宁强县| 和静县| 蓬溪县| 江川县| 吉木乃县| 吉木乃县| 福贡县| 浦县| 华坪县| 湘潭市| 上高县| 清流县| 皋兰县| 连州市| 锡林郭勒盟| 应城市| 内江市| 甘南县| 庆城县| 沙洋县| 苏尼特左旗| 若羌县| 会昌县| 岳普湖县| 荥经县| 桐乡市| 江达县| 宜城市| 天镇县| 三台县| 盐池县| 呼和浩特市| 和政县| 平山县|