COP2500 Assignment 8

Deliverables: To complete this assignment you must --
1.) Write the HTML and JavaScript page described below and demonstrate to the lab instructor that it operates correctly.

Introduction: The main goal of this assignment is for you to code the BubbleSort algorithms given in class and to see how they operate. In order to give you a good feel for how BubbleSort works we will create the ability to "step" through the algorithm slowly to see the effects of the compare-and-swap behavior.


Procedures:
  1. Use a text editor to complete your assignment.
  2. Save the source code of this page as "cop2500lab7.html" on your computer.
  3. Program the Swap(x, y) function, the Bubble() function, and the BubbleSort() function within "cop2500lab7.html". Use the algorithms given below.
  4. Open a browser and verify that everything works properly. Keep this window open until the instructor has had time to verify your work. In order to obtain full credit for the lab you need to email your source code to your grader, and you need to show him that it is working in the lab.

Algorithms:

Swap(x, y): The function that swaps two elements in an array.
SectionPseudocodeComments
Input: Integer list[12];
Integer x, y;
Assume list is a global variable
(declared outside the function).
Use a list of 12 elements.
x and y do not need to be
defined as they are in the
function name Swap(x, y),
Others: Integer temp; Local variable, temporary storage.
Initialization: List given to us
as a global variable.
x and y input as part of the function call.
Computation: temp = list[x];
list[x] = list[y];
list[y] = temp;
Output: Nothing to do here.

Bubble(): The function that passes through the array one time.
SectionPseudocodeComments
Input: Integer list[12]; Same global list is used
everywhere.
Others: Integer i; Local variable, loop counter.
Initialization: List given to us
as a global variable.
Computation: FOR i = 0 to 10 DO
   IF ( list[i] > list[i+1]) THEN
      swap( i, i+1 );
   ENDIF
ENDDO
Output: Post() The Post() function displays the results.

BubbleSort(): The main level program that puts it all togethor.
SectionPseudocodeComments
Input: Integer list[12]; Same global list is used
everywhere.
Others: Integer i; Local variable, loop counter.
Initialization: List given to us
as a global variable.
Computation: FOR i = 0 to 12 DO
   Bubble();
ENDDO
Output: Post() The Post() function displays the results.