Stack Flashcards

1
Q

Element access

top( )

A

accesses the top element
Parameters
(none)

Return value
Reference to the last element

Complexity
Constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Capacity

empty( )

A

checks whether the underlying container is empty
Parameters
(none)

Return value
true if the underlying container is empty, false otherwise

Complexity
Constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Capacity

size( )

A

returns the number of elements
Parameters
(none)

Return value
The number of elements in the container.

Complexity
Constant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Modifiers

push( )

A
inserts element at the top
Parameters
value	-	the value of the element to push
Return value
(none)

Complexity
Equal to the complexity of Container::push_back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Modifiers

emplace( )

A

constructs element in-place at the top
Parameters
args - arguments to forward to the constructor of the element
Return value
(none) (until C++17)
The value or reference, if any, returned by the above call to Container::emplace_back. (since C++17)
Complexity
Identical to the complexity of Container::emplace_back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Modifiers

pop( )

A

removes the top element
Parameters
(none)

Return value
(none)

Complexity
Equal to the complexity of Container::pop_back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Modifiers

swap( )

A
swaps the contents
Parameters
other	-	container adaptor to exchange the contents with
Return value
(none)

Exceptions
noexcept specification:
noexcept(noexcept(swap(c, other.c)))
In the expression above, the identifier swap is looked up in the same manner as the one used by the C++17 std::is_nothrow_swappable trait.

(since C++11)
(until C++17)
noexcept specification:  
noexcept(std::is_nothrow_swappable_v)
(since C++17)
Complexity
Same as underlying container (typically constant).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly