consider the following program : int array[]= { 10, 39, 1 , 4 , 100 ,56 }; void
ID: 3550183 • Letter: C
Question
consider the following program :
int array[]= { 10, 39, 1 , 4 , 100 ,56 };
void sort( int array [], int size){
bool swapped= true;
int temp;
for ( int i =1;( i<=size)&&( swapped); i++ ){
swapped = false;
for ( int j = 1; j<= (size -1 ); j++ ){
if ( array[j-1]> array[j];
{
temp= arry[j];
array[j]= array[j-1];
array[j-1] = temp;
swapped = value;
}
}
}
}
int main(){
sort (array,6)
for( int i =0 ; i< 6 ; i++ )
cout<< array[i]<< " ." ;
cout<< endle;
returno 0;
}
please explain it the above program is bubble sort, insertion sort, selection sort , or it quick sort . also please let me the output and explain it step by step about how did you get the answer and the reason for the output.
Explanation / Answer
Dear,
Some syntax errors identified in code and corrected to make the program execute:
Modified code:
// Header file section
#include <iostream>
using namespace std;
int arry[]= { 10, 39, 1 , 4 , 100 ,56 };
void sort( int array [], int size)
{
bool swapped= true;
int temp;
for ( int i =1;( i<=size)&&( swapped); i++ )
{
swapped = false;
for ( int j = 1; j<= (size -1 ); j++ ){
if ( arry[j-1]> arry[j])
{
temp= arry[j];
array[j]= array[j-1];
array[j-1] = temp;
swapped = true;
}
}
}
}
int main()
{
sort (arry,6);
for( int i =0 ; i< 6 ; i++ )
cout<< arry[i]<< " ." ;
cout<< endl;
return 0;
}
The sorting method is bubble sort implementation in which values are arranged in sorted order from lowest to highest.It compares sunsequent elemnts and then swaps.
The code will display : 1 .4 .10 .39 .56 .100 .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.