STL Internet and Web Resources

Answers to Self Review Exercises

23.1

False. These were avoided for performance reasons.

23.2

Associative.

23.3

Input, output, forward, bidirectional, random access.

23.4

False. It is actually vice versa.

23.5

True.

23.6

False. STL algorithms are not member functions. They operate indirectly on containers, through iterators.

23.7

True.

23.8

stack, queue, priority_queue.

23.9

False. It actually yields the position just after the end of the container.

23.10

Iterators.

23.11

Random-access.

Exercises

23.12

Write a function template palindrome that takes a vector parameter and returns TRue or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).

23.13

Modify Fig. 23.40, the Sieve of Eratosthenes, so that, if the number the user inputs into the program is not prime, the program displays the prime factors of the number. Remember that a prime number's factors are only 1 and the prime number itself. Every nonprime number has a unique prime factorization. For example, the factors of 54 are 2, 3, 3 and 3. When these values are multiplied together, the result is 54. For the number 54, the prime factors output should be 2 and 3.

23.14

Modify Exercise 23.13 so that, if the number the user inputs into the program is not prime, the program displays the prime factors of the number and the number of times each prime factor appears in the unique prime factorization. For example, the output for the number 54 should be

The unique prime factorization of 54 is: 2 * 3 * 3 * 3

Категории