/*Notes for sorting algorithm This program will have four sections. The first section assigns a random value to an array with 20 integers and displays the array to the screen. The Second section uses a for loop to copy the first array into the second array. The third section used a "bubble sort" to compare the contents of the second array. The bubble sort works by iterating down an array to be sorted from the first element in the index to the last, comparing each pair of elements and switching their positions if necessary. Because the inner loop will work its way through the entire array the largest value will work its way to the end of the array. Since the worst case scenario is that the array is in reverse order, and that the first element in sorted array is the last element in the starting array, the most exchanges that will be necessary is equal to the length of the array. The outer loop is therefore set to execute one less than the size of the array to be sorted.The last section uses a for loop to display the sorted contents of the second array.*/#include <iostream>#include <cstdlib> // Library used for random function rand()#include <ctime> // Time library used for random seed#include <iomanip> // Library used for bubble sortusing namespace std;int main() { int randarray[20] = {0}; // Initializing random array int sortarray[20] = {0}; // Initializing the sorting array int swap =0; // Initializing the swap variable // srand is used to seed the random loop. srand(time(NULL));// Formatting the Display with blank lines and title. cout << "Array 1 contents" << endl; cout <<"\n\n";// For loop that assigns a random number to each block of the array for(int i=0; i < 20; i++) { randarray[i] = rand(); cout << i << " = " << randarray[i] << endl; // Displays value of each block of the array } // For loop that copies the random array into the second array. for(int j=0; j < 20; j++) { sortarray[j] = randarray[j]; } // Formatting the Display with blank lines and title. cout <<"\n\n"; cout << "Array 2 contents sorted" << endl; cout <<"\n\n";// Bubble sort that loops through the array one less than its total amount. for(int k=0; k<19; k++) { for(int kk=0; kk<19; kk++) if(sortarray[kk] > sortarray[kk + 1]) // Compare the values and switch if necessary { swap=sortarray[kk]; sortarray[kk]=sortarray[kk + 1]; sortarray[kk + 1] = swap; } }// For loop to Display each block of the sorted array for(int l=0; l < 20; l++) { cout << l << " = " << sortarray[l] << endl; } return 0;}