Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new file named array _ ptrs . cpp and in this file, write a program that does the following: Defines an array of

Create a new file named array_ptrs.cpp and in this file, write a program that does the following:
Defines an array of integers called my_ints with a pre-specified size of 4.
Populates my_ints with input data provided by the user.
Defines an array of pointers called my_ptrs of the same size as my_ints and initializes the pointers in my_ptrs to point to corresponding elements of the array my_ints (refer to the Initial state of my_ptrs in the example shown below)
Sort the contents of the my_ptrs array in ascending order. You are allowed to use any existing sorting algorithm (two simple options are Bubble Sort and Insertion Sort; you may use either one or choose another one if you prefer). However, you are NOT allowed to use a library implementation of the algorithm. You must implement the algorithm from scratch.
What you have done above is to sort the values contained in the my_ptrs array, i.e., you have sorted memory addresses. Now, update your code to sort the my_ptrs array based on the integers that are being pointed to, i.e., the first element of my_ptrs should point to the smallest element in my_ints, the second element of my_ptrs should point to the next larger element in my_ints, etc. (refer to the State of my_ptrs after Step 2e in the example shown below). The my_ints array should NOT be changed in any way; the values should stay in the same position. You have already implemented this part of sorting from the steps above, but that was not using pointers, so now you need to sort it using pointers.
Traverse the array my_ptrs and print the values being pointed to by each pointer in this array.

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

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

How do books become world of wonder?

Answered: 1 week ago

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago