(Bubble Sort) In the bubble sort algorithm, smaller values gradually “bubble” their way up- ward to the top of the array like air bubbles rising in water, while the larger values sink to the bot- tom. The bubble sort makes several passes through the array. On each pass, successive pairs of elements are compared. If a pair is in increasing order (or the values are identical), we leave the values as they are. If a pair is in decreasing order, their values are swapped in the array. Write a program that sorts an array of 10 integers using bubble sort.
What will be an ideal response?
```
// This program sorts an array's values into ascending order.
#include
#include
using namespace std;
int main()
{
const int arraySize = 10; // size of array a
int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
int hold; // temporary location used to swap array elements
cout << "Data items in original order\n";
// output original array
for ( int i = 0; i < arraySize; i++ )
cout << setw( 4 ) << a[ i ];
// bubble sort
// loop to control number of passes
for ( int pass = 0; pass < arraySize - 1; pass++ )
{
// loop to control number of comparisons per pass
for ( int j = 0; j < arraySize - 1; j++ )
{
// compare side-by-side elements and swap them if
// first element is greater than second element
if ( a[ j ] > a[ j + 1 ] )
{
hold = a[ j ];
a[ j ] = a[ j + 1 ];
a[ j + 1 ] = hold;
} // end if
} // end for
} // end for
cout << "\nData items in ascending order\n";
// output sorted array
for ( int k = 0; k < arraySize; k++ )
cout << setw( 4 ) << a[ k ];
cout << endl;
} // end main
```
You might also like to view...
What would be the current directory if you issued the cd .. command at [analyst@sec- Ops home]$?
Create and change directories. a. Type pwd at the prompt.
[analyst@secOps ~]$ pwd /home/analystb. Navigate to the /home/analyst directory if it is not your current directory. Type cd /home/analyst
[analyst@secOps ~]$ cd /home/analystc. Type ls -l at the command prompt to list the files and folders that are in the current folder. Standing for list, the -l option displays file size, permissions, ownership, date of creation and more.
[analyst@secOps ~]$ ls -l total 20 drwxr-xr-x 2 analyst analyst 4096 Sep 26 2014 Desktop drwx------ 3 analyst analyst 4096 Jul 14 11:28 Downloads drwxr-xr-x 8 analyst analyst 4096 Jul 25 16:27 lab.support.files drwxr-xr-x 2 analyst analyst 4096 Mar 3 15:56 second_drive -rw-r--r-- 1 analyst analyst 254 Aug 16 13:38 space.txtd. In the current directory, use the mkdir command to create three new folders: cyops_ folder1, cyops_folder2, and cyops_folder3. Type mkdir cyops_folder1 and press Enter. Repeat these steps to create cyops_folder2 and cyops_folder3.
[analyst@secOps ~]$ mkdir cyops_folder1 [analyst@secOps ~]$ mkdir cyops_folder2 [analyst@secOps ~]$ mkdir cyops_folder3 [analyst@secOps ~]$e. Type ls -l to verify that the folders have been created:
[analyst@secOps ~]$ ls -l total 32 drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:01 cyops_folder1 drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:02 cyops_folder2 drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:02 cyops_folder3 drwxr-xr-x 2 analyst analyst 4096 Sep 26 2014 Desktop drwx------ 3 analyst analyst 4096 Jul 14 11:28 Downloads drwxr-xr-x 8 analyst analyst 4096 Jul 25 16:27 lab.support.files drwxr-xr-x 2 analyst analyst 4096 Mar 3 15:56 second_drive -rw-r--r-- 1 analyst analyst 254 Aug 16 13:38 space.txtf. Type cd /home/analyst/cyops_folder3 at the command prompt and press Enter.
[analyst@secOps ~]$ cd /home/analyst/cyops_folder3 [analyst@secOps cyops_folder3]$g. Use the mkdir command to create a new folder named cyops_folder4 inside the cyops_folder3 folder:
[analyst@secOps ~]$ mkdir /home/analyst/cyops_folder3/cyops_folder4 [analyst@secOps ~]$h. Use the ls -l command to verify the folder creation.
analyst@secOps ~]$ ls –l /home/analyst/cyops_folder3 total 4 drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:04 cyops_folder4i. Up to this point, we have been using full paths. Full path is the term used when referring to paths that always start at the root (/) directory. It is also possible to work with relative paths. Relative paths reduce the amount of text to be typed. To understand relative paths, we must understand the . and .. (dot and double) directories. From the cyops_folder3 directory, issue a ls –la:
analyst@secOps ~]$ ls –la /home/analyst/cyops_folder3 total 12 drwxr-xr-x 3 analyst analyst 4096 Aug 16 15:04 . drwxr-xr-x 20 analyst analyst 4096 Aug 16 15:02 .. drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:04 cyops_folder4The -a option tells ls to show all files. Notice the . and .. listings shown by ls. These listings are used by the operating system to track the current directory (.) and the parent directory (..) You can see the use of the . and .. when using the cd command to change directories. Using the cd command to change the directory to the . directory incurs no visible directory change as the . points to the current directory itself. j. Change the current directory to /home/analyst/cyops_folder3:
[analyst@secOps ~]$ cd /home/analyst/cyops_folder3 [analyst@secOps cyops_folder3]$k. Type cd .
[analyst@secOps cyops_folder3]$ cd . [analyst@secOps cyops_folder3]$l. Changing the directory to the .. directory, will change to the directory that is one level up. This directory is also known as parent directory. Type cd ..
[analyst@secOps cyops_folder3]$ cd .. [analyst@secOps ~]$
Users should not create controls that:
a) extend existent controls b) perform the same function as an existing control c) inherit from class UserControl d) a and c e) b and c
SSL encrypts the session, as well as the data that is being used in the session, using ____.?
A. ?PKI B. ?VPN C. ?TLS D. ?HTTPS
In a serial interface, what is the difference between a status of down and a status of administratively down?
What will be an ideal response?