Answered step by step
Verified Expert Solution
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#: missing ;
Error#: different type
ary to list
void insertionSort double list int size;
int main
double list;
int size ;
for int i ; i size; i
cout listi;
cout endl;
A call for the insertion sort function
int to double
ary to list
void insertionSort double list int size;
for int i ; i size; i
cout listi;
cout endl;
return ;
This function sorts an array in descending order
using the Insertion Sort algorithm
Function
void InsertionSortint numbers int size
Error #: different name as above; InsertionSort
Error #: different name as inside of function; int numbers
void insertionSort double ary int size
for int curr ; curr size; curr
make a copy of the current element
Element of function
temp arycurr;
Error #: missing int
int temp arycurr;
shift elements in the sorted part of the list to make room
Element of function
walk curr ;
Error #: missing int
int walk curr ;
Insertion sort
while walk && temp arywalk
Error #: should be
while walk && temp arywalk
arywalk arywalk;
Element of while loop
walk;
Error #: it should be decreased
walk;
put the copy of the current element back into the list
Element of function
arywalk temp;
Error #: missing
arywalk temp;
end of for: move to the next element to be inserted
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#: missing ;
Error#: missing
Error#: 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started