STL Flashcards Preview

CPP > STL > Flashcards

Flashcards in STL Deck (41)
Loading flashcards...
1

Size of vector

v.size()

2

Is vector empty

v.empty()

3

Vector of 10 vectors

vector< int > v[10];

4

Vector of size 10

vector< int > v(10);

5

Add new element to the vector

v.push_back(i);

6

Clear vector

v.clear()

7

Vector of 20 strings

vector< string > v(20, "Unknown");

8

N*M matrix filled with -1

vector< vector< int > > Matrix(N, vector< int >(M, -1));

9

Pass vector to function

void function(vector< int > &v);

10

Declare stack

stack< int > s;

11

Push to stack

s.push(i)

12

Pop from stack

s.pop()

13

Top of the stack

s.top()

14

Is stack empty

s.empty()

15

Size of stack

s.size()

16

Pair is defined in which header?

17

Access pair elemetns

P.first; P.second

18

c.end() points to ---- ?

The first invalid object right after the last element

19

c.begin == c.end means?

c.empty() is true

20

c.end() - c.begin() = ?

c.size()

21

reverse() and sort() take --- as parameters

container pointers eg. c.begin() or c.end()

22

Find 49 in and array(or vector)

find(v.begin(), v.end(), 49) != v.end()

23

Useful macro for all elements of container

#define all(c) c.begin(), c.end()

24

sort in reverse order

sort(c.rbegin(), c.rend());

25

traverse container beginning to end

#define tr(c, it) \
for(typeof(c.begin()) it = c.begin(), it != c.end(); it++)

26

Insert 42 in a vector at index 1

v.insert(1, 42);

27

Insert a new vector at index 1

v.insert(1, all(v2))

28

erase an element from vector

v.erase(iterator) NOT v.erase(index)

29

erase a range from vector

v.erase(begin iterator, end iterator)

30

substring

s.substr(0, s.length() - 1)