Assignment 1

1) Assume that you have a std::list of integers, and you want to sort them.
a) Write code to sort the list using the list::sort() member function.  Test it with some random numbers.
b) list::sort() is usually slower than the global std::sort() algorithm on a vector.  Write code to copy the data to a vector, sort it using the global sort() algorithm, then copy it back to the list.  To make it fun, do the copies without any explicit looping constructs.  (Use the vector constructor, assign(), or the std::copy algorithm with a back inserter iterator.)
Test the code with some random numbers.
c) To see if copying back and forth saves time, time the code in each case (use a large number of elements and/or time it in a loop).  When does it make sense to copy to a vector in order to sort the data?  What's the relative time difference, if any?
2) Write a program using STL containers and iterators to do the following:
Given two files named "in1.txt" and "in2.txt" consisting of the following lines:

in1.txt
-------
Santa Barbara
Berkeley
Santa Cruz
Irvine
Davis
-------

in2.txt
-------
Berkeley
Los Angeles
San Diego
Davis
-------

Produce a merged, sorted list of cities with duplicates removed (send to standard output).

a) Use std::list as the container, and use the specialized std::list member functions to do the sorting and duplicate removal.
b) Use std::vector as the container, and use global algorithms such as std::sort() and std::unique() to replace the specialized std::list member functions.  (Hint: Read the documentation for std::unique() carefully -- it doesn't do exactly the same thing as list::unique()!)