COMP2004 Programming Practice
2002 Summer School

Week 6 Monday Tutorial Exercises


  1. Rewrite the join() function from Question 6 of the Week 1 Friday tutorial so that it uses the ostrstream and/or ostringstream classes.

  2. The application of the istrstream or istringstream classes to Assignment 3 should be obvious.

  3. As promised in today's lecture, here are the rewrites of the hard-to-read code examples from the Bidirectional Iterator section of today's lecture. Hopefully these are easier to understand, though you might find drawing pictures of arrays/vectors make understanding how they work easier.
    template <typename BI, typename OI>
    OI reverse_copy(BI begin, BI end, OI out) {
    	while (begin != end) {
    		end--;
    		*out = *end;
    		out++;
    	}
    	return out;
    }
    
    template <typename BI>
    void reverse(BI begin, BI end) {
    	while (true) {
    		if (begin == end) break;
    		end--;
    		if (begin == end) break;
    		swap(*begin, *end);
    		begin++;
    	}
    }