In C++, Remove Duplicates From List

#include<iostream>
#include<list>

using namespace std;

void printList(list<int> ints){
	list<int>::iterator cur = ints.begin(), end = ints.end();
	cout << "list: {";
	while(cur != end){
		cout << *cur;
		cur ++;
		if(cur != end) cout << ", ";
	}
	cout << "}" << endl;
}

int main(){
	list<int> intList = {3, 23, 23, 43, 56, 11, 11, 23, 25};
	printList(intList);
	intList.unique();
	printList(intList);
	return 0;
}

Comments

Popular posts from this blog