home | login | register | DMCA | contacts | help | 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
А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я


my bookshelf | genres | recommend | rating of books | rating of authors | reviews | new | форум | collections | читалки | авторам | add
fantasy
space fantasy
fantasy is horrors
heroic
prose
  military
  child
  russian
detective
  action
  child
  ironical
  historical
  political
western
adventure
adventure (child)
child's stories
love
religion
antique
Scientific literature
biography
business
home pets
animals
art
history
computers
linguistics
mathematics
religion
home_garden
sport
technique
publicism
philosophy
chemistry
close

Loading...


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







Loading...