Question: Program 6: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving

 Program 6: Sorting with Pointers Sometimes we're given an array of

data that we need to be able to view in sorted order

while leaving the original order unchanged. In such cases we could sort

the data set, but then we would lose the information contained in

the original order. We need a better solution. One solution might be

Program 6: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make a copy of one array into another, and then to sort the second array. This would allow us to view the data both in the original order and in the sorted order. This might be fine in many cases, but redundancy is frequently problematic. A more elegant solution is to sort the array indirectly, i.e., by using pointers. With this technique we wouldn't change the positions of the actual data items in the array; we would only change the values of the pointers that point into the array. Nevertheless, when this type of sorting is performed, we still will be able to access the data both in its original order, by using the original array, but also in sorted order, by using the array of pointers. Here a are some diagrams that illustrate the idea: arrPtr Array donations Array arrPtr Array doations Array 101 (31 13] 141 [51 [61 The book from which these diagrams were taken called the array containing the original data set the "donations Array," but that is not relevant to our current problem. What is depicted here is the original data set contained in the array on the right in each picture, and an array of pointers pointing at various elements of the original data set on the left in each picture. We first initialize the array of pointers so that each element in the pointer array points to the element in the data array that has the same index value (left hand picture). We then sort the pointers according to the values they point to, leaving the original data set untouched (right hand picture). After this step is completed, we can access the data set in its original order by using the original array, or we can access the data set in sorted order through the pointer array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this problem you need to write a program in C that sorts an array using pointers while keeping the original array unchanged The task involves ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!