Answered Essay: Create a file named lab3.c. Copy the following code into your program. This is the initial versio

Create a file named lab3.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 1. The comments are there to show examples of what you might do to test your other functions. #include <stdio.h> #include <stdlib.h> #include heloe r functions . h #include sortingfunctions.n” #define ARRAYSIZE 10 int main (void) { // dynamically allocate nemory space for an array in. * arrayPtr = (int *) malloc (ARRAYS I ZE sizeof ( int));

Create a file named lab3.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 1. The comments are there to show examples of what you might do to test your other functions. #include #include #include “heloe r functions . h” #include “sortingfunctions.n” #define ARRAYSIZE 10 int main (void) { // dynamically allocate nemory space for an array in. * arrayPtr = (int *) malloc (ARRAYS I ZE sizeof ( int));

Expert Answer

 

// main program

#include <stdio.h>
#include <stdlib.h>
# include “sortingfunctions.h”
# include “helperfunctions.h”
# define ARRAYSIZE 10

int main(int argc, char** argv) {
int i;
// dynamically allocate memory space for an array
int *arrayPtr = (int *) malloc(ARRAYSIZE*sizeof(int));
fillArray(arrayPtr, ARRAYSIZE, 20, 50);
neatPrint(arrayPtr, ARRAYSIZE, 10, 3);
int ct = selectionSort(arrayPtr, ARRAYSIZE);
printf(“n the number of swapping in selection sort is :%dn”,ct);
neatPrint(arrayPtr, ARRAYSIZE, 10, 3);

printf(“n insertion sort n”);
fillArray(arrayPtr, ARRAYSIZE, 20, 50);
neatPrint(arrayPtr, ARRAYSIZE, 10, 3);
int cnt = insertionSort(arrayPtr, ARRAYSIZE);
printf(“n the number of swapping in insertion sort is :%d”,cnt);
neatPrint(arrayPtr, ARRAYSIZE, 10, 3);

return (EXIT_SUCCESS);
}

//sortingfunction.c

# include “sortingfunctions.h”

#include<stdio.h>

int selectionSort(int *const data, int size)

{

int i,j,min,*swap;

int count;

for (i = 0; i < size; i++)

{

min = i;

for ( j = i + 1 ; j < size ; j++ )

{

if ( *(data+min) > *(data+j) )

min = j;

}

if ( min != i )

{

count++;

*swap = *(data+i);

*(data+i) = *(data+min);

*(data+min) = *swap;

}

}

/* for (i = 0; i < size; i++)

{

min = i;

for ( j = i+1; j < size; j++)

{

if (*(data+j) < *(data+i))

min = j;

}

if (min != i) {

int *temp;

count++;

temp = *(data + i);

*(data + i) = *(data + min);

*(data + min) = temp;

}

}

printf(“Got in”);

for (i = 0; i < size; i++)

printf(“t%d”, *(data + i));*/

return count;

}

int insertionSort(int *const data, int size) {

int i = 1;

int j = i;

int t;

int count = 0;

for (i = 1; i < size; ++i) {

for (j = 0; j < size; ++j) {

if ( *(data + i)< *(data + j)) {

count++;

t = *(data + i);

*(data + i) = *(data + j);

*(data+j) = t;

}

}

}

return count;

}

//helperfunctions.c

#include “helperfunctions.h”
#include <stdlib.h>
# include <stdio.h>

void swap(int *num1, int * num2) {
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}

void fillArray(int * const data, int size, int min, int max) {
int i;
for (i = 0; i < size; i++) {
*(data + i) = rand() % (max – min + 1) + min;

}
}

void neatPrint(int *const data, int size, int numPerLine, int fieldSize) {
int i;
printf(“n”);
for (i = 0; i < size; i++) {
printf(“t%d”, *(data + i));
if (i == numPerLine)
printf(“n”);
}
}

//sortingfunctions.h
#ifndef SORTINGFUNCTIONS_H
#define SORTINGFUNCTIONS_H

int selectionSort(int * const data, int size);
int insertionSort(int * const data, int size);

#endif /* SORTINGFUNCTIONS_H */

//helperfunctions.h

#ifndef HELPERFUNCTIONS_H
#define HELPERFUNCTIONS_H

#ifdef __cplusplus
extern “C” {
#endif

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);

#ifdef __cplusplus
}
#endif

#endif /* HELPERFUNCTIONS_H */

sample output:

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?