Reading

None.

Reinforcement

This lecture is to be used to reinforce the previous lecture on sorting and searching. We'll go over the homework very thoroughly, and try and really internalize the following:

Problems
  1. Write a program that reads in a list of 3D points (x,y,z) and prints them out in increasing distance from the origin. The points should be represented as arrays of length 3. Here's my solution. Below is a sample run of the program:
    How many points? 3
    Enter points (x,y,z): (1,0,1) (1,0,-1.2) (-1,1,-1)
    (1,0,1) (1,0,-1.2) (-1,1,-1) 
    	    

    • Try the same thing, but sort by x-values, breaking ties by y-values, breaking those ties by z-values.
    • Try the same thing, but sort in increasing order of distance from a point given by the user.

  2. Write a program that reads in a list of 3D points (x,y,z), then reads in a point p and a distance d from the user, and then prints a point from the list that lies within distance d of point p ... if it exists.

Asst Prof Christopher Brown
Last modified: Tue Nov 2 15:14:13 EST 2004