Vector Flashcards

1
Q

How do you implement In order traversal?

A

Base case: check if node is null. Recursion through all left subtree, print the node, then recursion through right subtree.

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

How to initialize an empty std::vector in c++?

A

std::vector<int> vect;</int>

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

How to add a value to a std::vector in c++?

A

vect.push_back(x);

where x is some value.

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

How to initialize a std::vector with initial values in c++?

A

std::vector<int> vect{10, 20, 30};</int>

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

What is a quick way to loop through all items in a std::vector using a for loop and : ?

A

for (int x : vect)
cout &laquo_space;x &laquo_space;” “;

where int is the type of vector.

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

How to create a std::vector with size n and all initialized to the same value?

A

std::vector<int> vect(n, value) ;</int>

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

What are access specifiers in c++?

A

Keywords that define the accessibility or visibility level of class members.

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

What is the default access specifier for c++ classes?

A

By default, class members are private.

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