Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

resize.c: sort.c: 1. In sort.c we have implemented a basic version of insertion sort. Compile and run the code to make sure it works. Now,

image text in transcribed

resize.c:

image text in transcribed

sort.c:

image text in transcribed

image text in transcribed

1. In sort.c we have implemented a basic version of insertion sort. Compile and run the code to make sure it works. Now, replace all array index access in the entire program by using pointer addition instead. Also, implement array creation using malloc. Make sure your program compiles and runs correctly (numbers are sorted). 2. The purpose of resize.c is to create an initial array of a user-specified size, then dynamically resize the array to a new user-specified size. However, the code is missing a few things. You must manage the memory for the array! Look at the comments in the code that describe what should be done and fill in blanks. Make sure the program compiles and runs as expected. #include #include int main(){ //Allows you to generate random number srand(time(NULL)); // Allows user to specify the original array size, stored in variable ni. printf("Enter original array size:"); int n1=0; scanf("%d",&n1); //Create a new array of ni ints int* a1 = /* Fill in*/ int i; for(i=0; i #include #include 1/Sort an array A using insertion sort. Notice it is to be passed by reference. void sort(/* what's the argument data type?*/ A, int n){ int tmp; int i; int i; for(i=1; i=0){ A[j+1)=A[j]; j-=1; } A[j+1]=tmp; } int main(){ //Allows use to generate random numbers srand(time(NULL)); //Read a user input integer and store it in n int n; printf("Enter an integer n: "); scanf("%d",&n); //Array array. Change this to become a dynamic array through malloc. int array[n]; //Assign each element in the array a random number between 0 and 31,999 int i; for (i=0; i<><><1>

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

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago