COP2500 Assignment 9

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 "cop2500lab9.html" on your computer.
  3. Write the code for the Swap(x, y) function, the Bubble() function, and the BubbleSort() function within "cop2500lab9.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 labs not graded during the class time you need to submit this assignment via webct by 10 p.m. on Monday 16, July.

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 the parameters of the function 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
You do not need to write this function it is already done for you .

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 11 DO
Bubble();
ENDDO
Output: Post() The Post() function displays the results.