Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; / / Function declaration / / void insertionSort ( double ary, int size ) / / Error# 1 : missing ;

#include
using namespace std;
// Function declaration
// void insertionSort( double ary, int size)
// Error#1: missing ;
//Error#2: different type
//ary to list
void insertionSort( double list[], int size);
int main()
{
double list[100]={50.1,70.5,30.2,80.3,10.5,30.2,40.9,90.8,30.2,80.8,30.5};
int size =11;
for (int i =0; i < size; i++)
{
cout << list[i]<<"";
}
cout << endl;
// A call for the insertion sort function
//int to double
//ary to list
void insertionSort( double list[], int size);
for (int i =0; i < size; i++)
{
cout << list[i]<<"";
}
cout << endl;
return 0;
}
/***************************************************
This function sorts an array in descending order
using the Insertion Sort algorithm
*/
//Function
//void InsertionSort(int numbers[], int size)
//Error #2: different name as above; InsertionSort
//Error #3: different name as inside of function; int numbers[]
void insertionSort( double ary[], int size){
for (int curr =1; curr < size; curr++)
{
// make a copy of the current element
//Element of function
//temp = ary[curr];
//Error #4: missing int
int temp = ary[curr];
// shift elements in the sorted part of the list to make room
//Element of function
//walk = curr -1;
//Error #5: missing int
int walk = curr -1;
//Insertion sort
//while( walk >=0 && temp < ary[walk])
//Error #6: < should be >
while( walk >=0 && temp < ary[walk])
{
ary[walk +1]= ary[walk];
//Element of while loop
//walk++;
//Error #7: it should be decreased
walk--;
}
// put the copy of the current element back into the list
//Element of function
//ary[walk1]= temp;
//Error #6: missing +
ary[walk +1]= temp;
}// end of for: move to the next element to be inserted
}
1.13 Lab: Insertion Sort (find errors)
The following program is a test driver for the Insertion Sort function: It should sort an array of doubles in descending order, but and it has some errors (syntax and logical)
Find and fix them as shown below:
// Function declaration
void insertion Sort( double ary, int size)
mark the errors
comment the line
write the correction below
Eg.
// Function declaration
// void insertion Sort( double ary, int size)
// Error#1: missing ;
// Error#2: missing []
// Error#3: bad function name - it contains a space
void insertionSort( double ary[], int size);
Hint: read all comments carefully!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions