Ein vector bietet schnellen, indizierten Zugriff auf die
Elemente. Dafür kostet Einfügen und Löschen viel Rechenzeit, sofern es
nicht am Ende des Vektors stattfindet..
#include <vector>
const int x[] = { 2, 3, 5, 7, 11, 13, 17, 23 };
std::vector<int> v (x, x + sizeof (x));
Eine list erfordert langsames, lineares Suchen von
Elementen. Dafür ist das Einfügen und Löschen Vorne und Hinten sowie
an einer bekannten Position sehr schnell.
(std::string & s,
size_type first = 0,
size_type last = std::string::npos);
Umwandlung aus String
bitset &
operator&=
(const bitset & b);
Löscht alle Bits, die nicht in b gesetzt sind.
bitset &
operator|=
(const bitset & b);
Setzt alle Bits, die in b gesetzt sind.
bitset &
operator^=
(const bitset & b);
Exklusive ODER-Verknüpfung
bitset &
operator<<=
(size_type n);
Schiebt die Bits um n Positionen nach links.
bitset &
operator>>=
(size_type n);
Schiebt die Bits um n Positionen nach rechts.
bitset
operator<<
(size_type n) const;
Kopie um n Positionen nach links verschobene.
bitset
operator>>
(size_type n) const;
Kopie um n Positionen nach rechts verschobene.
bitset
operator~
() const;
Liefert das Komplement.
bitset &
set
();
Setzt alle Bits auf 1
bitset &
set
(size_type pos, int val = 1);
Setzt das Bit an Position pos auf den Wert val.
bitset &
reset
();
Löscht alle Bits
bitset &
reset
(size_t pos);
Löscht das Bit an Position pos.
bitset
flip
(size_t pos);
Invertiert das Bit an Position pos.
Kapazität
size_type
size
() const;
Liefert die Anzahl Bits.
Elementzugriff
bool
operator[]
(size_type index);
Liefert den Wert eines bestimmtes Bits.
Bitset-Operationen
size_type
count
() const;
Liefert die Anzahl gesetzter Bits.
bool
test
(size_t pos) const;
Ist das Bit an Position pos gesetzt?
bool
any
() const;
Ist mindestens ein Bit gesetzt?
bool
none
() const;
Ist kein Bit gesetzt?
unsigned long
to_ulong
() const;
Umwandlung in Zahl
std::string
to_string
() const;
Umwandlung in String
Assoziative Container (Dictionaries)
Sortierte Menge
In einem set kommt jedes Element nur einmal vor. In
einem multiset können Elemente auch mehrfach vorkommen.
Die Elemente sind immer aufsteigend sortiert.
Iteratoren bleiben beim Einfügen und Löschen gültig.
In einer map kommt jeder Schlüssel nur einmal vor. In
einer multimap können Schlüssel auch mehrfach vorkommen.
Die Elemente sind immer aufsteigend nach Schlüsseln sortiert.
Iteratoren bleiben auch beim Einfügen und Löschen gültig.