Assignment 7 - Bubble Sort

  1. Download page.
    Download this page onto your computer and place it on your webpage.
    Look with an editor at the file. The following commands can be used.
              cd ~/public_html
              wget http://www.comp.nus.edu.sg/~gem1501/assignment07.html
              chmod 755 *.html 
  2. Implement the Bubble Sort Algorithm.
    The algorithm is on pages 21-23 in Chapter 2 of Harel's Book.
    There is a "document.write" statement at the place of the missing part.

  3. Keep track of what the algorithm is doing.
    Write out all intermediate values during the sorting process.

  4. Bring algorithm in final form.
    Modify the program such that it stops sorting whenever in one round no pairs of list elements are exchanged.
    You can use the variable "ready" to track that event down.
    For this, you have to delete one appropriate line.
    How many rounds does the sorting then need?

  5. Self-Assessment.
    After the fifth round, the output should look like this.

    The number of rounds is less than the number of words.
Java Script Starts Here.


Java Script Ends Here.