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

  • Mastering C++ Programming
  • Jeganathan Swaminathan
  • 70字
  • 2021-07-02 18:28:51

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();
主站蜘蛛池模板: 广南县| 文登市| 商丘市| 青海省| 芮城县| 黔西| 岳阳县| 淄博市| 锡林郭勒盟| 太仓市| 贡山| 志丹县| 安化县| 肃南| 卢湾区| 阿克陶县| 沂源县| 蓝山县| 武功县| 穆棱市| 河源市| 海阳市| 金秀| 洞头县| 襄樊市| 德保县| 固原市| 江都市| 德庆县| 潼南县| 称多县| 日喀则市| 海伦市| 青冈县| 文安县| 太仆寺旗| 中宁县| 汶川县| 改则县| 温泉县| 治县。|