Lecture 20 Flashcards

1
Q

In C++, there is a vector class as part of the

A

std namespace.

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

Arrays

A

–Good for adding items to the end of lists and for random access to items within the list.
–Bad for cases with many additions and removals at various places within the list.

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

Linked Lists

A

–Better for adding and removing items at random locations within the list.
–Bad at randomly accessing items from the list.

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

What is the function of an iterator?

A

to get each contained object in order, one at a time, in a controllable manner.

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

the iterator code

A
vector numbers;
// omitted code initializing numbers.
iterator iter;
for(iter = numbers.begin();
iter != numbers.end(); iter++)
{
cout << *iter << ‘ ’;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In C++, iterators are designed to look like and act something like pointers.

A

The * and -> operators are overloaded to give pointer-like semantics, allowing users of the iterator object to “dereference” the object currently “referenced” by the iterator.

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

Both the std::vector and std::list classes of C++ implement iterators.

A

–begin() returns an iterator to the list’s first element.
–end() is a special iterator “just after” the final element of the list, useful for checking when we’re done with iteration.

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

Stacks

A

“Last In, First Out” (LIFO) structure.
–That is, the last input to the structure is the first output obtained from it.
–Consider a stack of papers: when searching through it, one typically starts at the top and searches downward, from newest to oldest.

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

Stacks are a very good model for

A
function calls.
–Stacks are the model of how recursion mechanically works.
–In turn, recursion is necessary for operating upon many data structures.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The data structure known as a queue is a

A

“First In, First Out” (FIFO) structure.
–That is, the first input to the structure is the first output obtained from it.
–Consider a line of people: the person in front has priority to whatever the line is waiting on… like buying tickets at the movies or gaining access to a sports event.

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

Queues are significantly like lists, except

A

that we have additional restrictions placed on them.
–Additions may only happen at the list’s end.
–Removals may only happen at the list’s beginning.

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

The “deque”, or double-ended queue, combines

A

the behaviors of stacks and queues into a single structure.
–Items may be added or removed at either end of the structure.
–This allows for either LIFO or FIFO behavior
– it’s all in how you use the structure.
–Mixed behavior is also possible, so beware!

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

Math done in “standard” (i.e, infixnotation) is typically

A

first converted to postfix notation for actual computation.

–This “conversion” is known as the Shunting-yard algorithm.

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

Uses of the C++ std::stack class

A

–This implementation is something of a “wrapper class” that uses a vector, list, or deque internally, limiting it to stack-like behavior.
–We’ll see deques in a moment.
–The methods push_back(), pop_back(), and back() are designed from a stack perspective.

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