CPSC 170 PreLab 3

  1. Sort the array shown using each algorithm below. In each case, show the array after each step, whether or not anything in the array changes.
    7  2  9  1  3  4  6
    
    1. Selection sort









    2. Insertion sort









  2. Look at the code for insertion sort in listing 9.9. In the insertionSort method, what would happen if the index started at 0 instead of 1? (Note that the compareTo method simply tells which of two objects is larger; we'll talk about it soon.)






  3. Read section 7.9 in the text on Mouse Events and answer the following questions.
    1. What action(s) cause each event below to be generated? Be sure you clearly distinguish how the last is different from the first two.
      • mouse pressed

      • mouse released

      • mouse clicked

    2. In the DotsPanel class in listing 7.19 there is an inner class called DotsListener. In the mousePressed method of this class, what information does the call to event.getPoint() provide? (This method refers to an ArrayList object called pointList. We have not talked about the ArrayList class, but just think of it as representing a list with methods to add items to and iterate over the list.)





    3. Also in the DotsListener inner class:
      1. Why are there empty definitions for mouseClicked, mouseReleased, mouseEntered, and mouseExited? (You may wish to refer to section 6.5 on interfaces.)





      2. What would happen if we took these out?