Bubble Sort Lab
Create an array and initialize it with the numbers 12, 9, 13, 5, and 10. You will now play computer. You must evaluate each statement and supply the values for the various variables, make the decisions and do any processing that might be necessary. I have supplied the code below for the bubble sort which you will "walk" through while you are doing the same processing that your computer would do. 
We will start with just the for loop.
 1. swapped = false;
 2. for (i = 0; i < SIZE -1; i++) {
 3.	if (array[i] > array[i+1]) {
 4.	    //switch the elements' (numbers) order in the array
 5.	    hold = array[i];
 6.	    array[i] = array[i+1];
 7.	    array[i+1] = hold;
 8.	    swapped = true;
 9.	}
10. }

1.	Using the for loop as given above, and the value you have stored in your array, read the code line by line and fill in the current value for each variable as the code progresses. We are working with five numbers, so the for loop will run 4 times. A table is provided for each iteration of the loop.
Current values in the array at the start.
Index 0	Index 1	Index 2	Index 3	Index 4	
					
Fill in the table with the correct values as you walk through the code.  array[i] > array[i+1] will evaluate to true or false. Just put a line through the cells for lines 7 and 8 if it evaluates to false. 
Line number	2	3	3	3	5	6	7	8	
Variable	i	 array[i]	array[i+1]	array[i] > array[i+1]	hold	array[i]	array[i+1]	swapped	
value									
Current values in the array after iteration 1.
Index 0	Index 1	Index 2	Index 3	Index 4	

Line number	2	3	3	3	5	6	7	8	
Variable	i	 array[i]	array[i+1]	array[i] > array[i+1]	hold	array[i]	array[i+1]	swapped	
value									
Current values in the array after iteration 2.
Index 0	Index 1	Index 2	Index 3	Index 4	

Line number	2	3	3	3	5	6	7	8	
Variable	i	 array[i]	array[i+1]	array[i] > array[i+1]	hold	array[i]	array[i+1]	swapped	
value									

Current values in the array after iteration 3.
Index 0	Index 1	Index 2	Index 3	Index 4	

Line number	2	3	3	3	5	6	7	8	
Variable	i	 array[i]	array[i+1]	array[i] > array[i+1]	hold	array[i]	array[i+1]	swapped	
value									
Current values in the array after iteration 4.
Index 0	Index 1	Index 2	Index 3	Index 4	

2.	Why does the loop test use i < SIZE - 1 instead of i < SIZE ? 
3.	
Is the array sorted?
4.	Now we will add the do...while loop. Fill in the values for the variables while evaluating the do...while loop. You have already done one repetition of the for loop. For the first run of the do while, put your beginning array values into the cells and the last values into the cells in the appropriate spaces in the chart below. You may not have to use all the runs of the do while loop that are provided. 
 1. do { 
 2.     swapped = false;
 3.     for (i = 0; i < SIZE -1; i++) {
 4.         if (array[i] > array[i+1])
 5.             //switch the elements order in the array
 6.             hold = array[i];
 7.             array[i] = array[i+1];
 8.             array[i+1] = hold;
 9.             swapped = true;
10.         }
11.     }
12. } while(swapped == true);

Fill in the following table with your values 	
First run of do while loop	

do {	

    array values  (before for) 	

	

    swapped (before for) 	

     for loop runs to completion	

    array values (after for) 	

	

    swapped (after for)	

} while (swapped == true);	

	
Second run of do while loop	

do {	

    array values  (before for) 	

	

    swapped (before for) 	

     For loop runs to completion	

    array values (after for) 	

	

    swapped (after for)	

} while (swapped == true);	

	

Third run of do while loop	

do {	

    array values  (before for) 	

	

    swapped (before for) 	

     for loop runs to completion	

    array values (after for) 	

	

    swapped (after for)	

} while (swapped == true);	

	

Fourth  run of do while loop	

do {	

    array values  (before for) 	

	

    swapped (before for) 	

     for loop runs to completion	

    array values (after for) 	

	

    swapped (after for)	

} while (swapped == true);	

	

Fifth  run of do while loop	

do {	

    array values  (before for) 	

	

    swapped (before for) 	

     for loop runs to completion	

    array values (after for) 	

	

    swapped (after for)	

} while (swapped == true);	

	
5.	When does the do/while loop stop repeating?