Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MUST BE DONE IN C, NOT C++ OR OTHER LANGUAGES Modify the insertion sort program developed in Assignment #2 (just a regular insertion sort algo

MUST BE DONE IN C, NOT C++ OR OTHER LANGUAGES

Modify the insertion sort program developed in Assignment #2 (just a regular insertion sort algo for C) such that the program now sorts strings (array of characters) instead of integers and uses dynamic memory allocation to allocate memory based on the number of elements in the array as well as the length of individual strings. You can use scanf function to first read the number of strings that will be entered (say, N) and then allocate an array of size N that stores a pointer to a character. Then use a loop to read each string, determine the length of the string, and then allocate appropriate amount of memory for each string, store the reference of the memory allocated in the array of pointers created earlier, and then copy the string read into the allocated memory. Note that you have make an explicit copy of the string that you read into the memory allocated since the buffer used to read the string will be overwritten when the next string is read. Remember to free the memory allocated for each string and the array of pointers. Use separate functions to read the strings, sort the strings, and display the sorted strings. Here is a sample function prototype:

/* function to read an array of strings */ void readarray(char *arr[], int N); /* function to print an array of strings */ void printarray(char *arr[], int N); /* function to sort the array of strings using insertion sort algorithm */ void insertionsort(char *arr[], int N);

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

Step: 3

blur-text-image

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

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

I wasnt sure how to talk about this situation. It was too personal.

Answered: 1 week ago