Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The are many different ways to sort data. For some applications, e . g . , making movies, it is better to sort pointers to
The are many different ways to sort data. For some applications, eg making movies, it is better to sort pointers to the data, rather than sort the data itself. You must write a program to demonstrate this kind of activity. The program must
Define data types for
A pointer to an integer
An array of five integers
An array of five pointers to integers
Have an intialization function that
Initializes the elements of an array of five integers to random integers. Use rand to generate the random integers, using srand with the return from getpid to seed the random number generation.
Initializes the elements of an array of five pointers to integers to point to the corresponding elements of the array of integers. The structure is anaolgous to the one created in this example that we discussed in class.
Have a function that prints an array of five integers.
Have a function that prints the integers pointed to by an array of five pointers to integers.
Have a function that uses a bubblesort to sort an array of five integers, in ascending order of the integers.
And to make it fun, try do it without any ed array accesses.
Have a function that uses a bubblesort to sort an array of five pointers to integers, in ascending order of the integers pointed to by the pointers ie do not sort the integer array sort the array of pointers so that when you print it the integers come out in ascending order
Have a main function that
Declares an array of five integers and an array of five pointers to integers.
Initializes the arrays as described above
Prints the array of integers.
Sorts the array of pointers as described above
Prints the integers pointed to by the array of pointers.
Sorts the array of integers.
Prints the array of integers.
Prints the integers pointed to by the array of pointers.
The output from a sample run should look like this. The picture on the right shows the array of integers and array of pointers after intialization, sorting the array of pointers, and sorting the array of integers.
Initialized array of integers
:
:
:
:
:
Sorted array of pointers
:
:
:
:
:
Sorted array of integers
:
:
:
:
:
Array of pointers
:
:
:
:
:
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