на главную | войти | регистрация | DMCA | контакты | справка | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я


моя полка | жанры | рекомендуем | рейтинг книг | рейтинг авторов | впечатления | новое | форум | сборники | читалки | авторам | добавить



Example

Remove duplicates from consecutive groups of equal int s.

vector V;

V.push_back(1);

V.push_back(3);

V.push_back(3);

V.push_back(3);

V.push_back(2);

V.push_back(2);

V.push_back(1);

vector::iterator new_end = unique(V.begin(), V.end());

copy(V.begin(), new_end, ostream_iterator(cout, " "));

// The output it "1 3 2 1".

Remove all duplicates from a vector of char s, ignoring case. First sort the vector, then remove duplicates from consecutive groups.

inline bool eq_nocase(char c1, char c2) { return tolower(c1) == tolower(c2); }

inline bool lt_nocase(char c1, char c2) { return tolower(c1) < tolower(c2); }


int main() {

 const char init[] = "The Standard Template Library";

 vector V(init, init + sizeof(init));

 sort(V.begin(), V.end(), lt_nocase);

 copy(V.begin(), V.end(), ostream_iterator(cout));

 cout << endl;

 vector::iterator new_end = unique(V.begin(), V.end(), eq_nocase);

 copy(V.begin(), new_end, ostream_iterator(cout));

 cout << endl;

}

// The output is:

// aaaabddeeehiLlmnprrrStTtTy

// abdehiLmnprSty


Complexity | Standard Template Library Programmer`s Guide | Notes