Lecture 20 Flashcards Preview

COP3503 > Lecture 20 > Flashcards

Flashcards in Lecture 20 Deck (14):
1

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

std namespace.

2

Arrays

–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.

3

Linked Lists

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

4

What is the function of an iterator?

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

5

the iterator code

vector numbers;
// omitted code initializing numbers.
iterator iter;
for(iter = numbers.begin();
iter != numbers.end(); iter++)
{
cout << *iter << ‘ ’;
}

6

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

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.

7

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

–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.

8

Stacks

“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.

9

Stacks are a very good model for

function calls.
–Stacks are the model of how recursion mechanically works.
–In turn, recursion is necessary for operating upon many data structures.

10

The data structure known as a queue is 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.

11

Queues are significantly like lists, except

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.

12

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

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!

13

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

first converted to postfix notation for actual computation.
–This “conversion” is known as the Shunting-yard algorithm.

14

Uses of the C++ std::stack class

–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.