Question
PLEASE HELP! Complete functions and main code in C language. THANK YOU! 1.Create a file named pa5.c. Copy the following code into your program. This
PLEASE HELP! Complete functions and main code in C language. THANK YOU!
1.Create a file named pa5.c. Copy the following code into your program. This is the initial version of your "test program". You will modify this file as you go through the process of writing and testing the functions in this assignment.
The comments are there to show examples of what you might do to test your other functions.
#include
#include
#include "sortingfunctions.h"
#define ARRAYSIZE 10
int main (void) {
// dynamically allocate memory space for an array
int * arrayPtr = (int *) malloc (ARRAYSIZE* sizeof(int));
// fill the array with random integers
// print the array, 10 elements per line
// sort the array using selection sortand print the return value
// print the array, 10 elements per line
// fill the array again with random integers
// print the array// sort with insertion sort and print the return value
// print the array
}
2.Create a file called sortingfunctions.h Write a preprocessor wrapper (following convention for constant name) and then insert the following prototypes.
intselectionSort ( int * const array, int size );
intinsertionSort ( int * const array, int size );
void swap( int * num1, int * num2);
void fillArray( int * const data, int size, int min, int max);
void neatPrint( int * const data, int size, int numPerLine, int fieldSize);
3.Create a file called sortingfunctions.c Write the implementation of the five functions.
int selectionSort ( int * const data, int size );
sorts the array using the selection sort algorithm
You cannot use the bracket [ ] notation to access array elements. You have to use pointer/offset notation.
The return value is a count of the number of comparisons that are made. Specifically, you should count the number of times that the program executes if statement that compares the values of two array elements.
int insertionSort ( int * const data, int size );
sorts the array using the insertion sort algorithm
You cannot use the bracket [ ] notation to access array elements. You have to use pointer/offset notation.
The return value is a count of the number of comparisons that are made. Specifically, you should count the number of times that the program executes if statement that compares the values of two array elements.
void swap( int * num1, int * num2);
Exchanges the contents of the two memory locations.
voidfillArray( int * const data, int size, int min, int max);
Fills the array elements with integers from min to max (inclusive).
You cannot use the bracket [ ] notation to access array elements. You have to use pointer/offset notation.
void neatPrint ( int * const data, int size, int numPerLine, int fieldSize );
Prints the array elements in nice, neat columns using the parameters numPerLine and fieldSize to control the layout.
You cannot use the bracket [ ] notation to access array elements. You have to use pointer/offset notation.
4.Compile, test, and debug your program as needed.
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