I have a question about programming in C(89) C. Could someone please show me how to make a program that uses a custom function that rearranges array elements from one array of size n into a new larger second array of size (n+1) and places a new element into the new second larger array at a particular index location? For example, the user would be prompted for a size like say, 7. Then the user would be prompted for the seven array element values, which could be like {1, 7, 4, 6, 3, 9, 8}. Then the user gets prompted again for a new element value to add to the new larger second array. Let's say the new value is entered as 5. All of this would be done in main and no pointers are required. Then main calls a custom function called rearrange. the prototype for rearrange must be; void rearrange(int *a, int n, int insert, int *b);   After rearrange is done, main would display the contents of the new larger second array like so;   {1, 4, 3, 5, 7, 9, 8} Here's the trick though. Please notice how all the numbers lower than the new element 5 are still in the same order as the first array and that all the elements with values higher than 5 are in the same order as the original array. Here are my feelings about the logic of the custom function rearrange. I feel like a counter variable counts the number of elements lower than the new value (say 5) so that the new value (5) can be placed at the correct index location (3) in the new array named b. I think that a while loop with a conditional if could be used with a pointer to guide the elements of the first array a that are less than or equal to the new value (the 5) into the new larger second array named b. And finally, another while loop with a conditional if walks through the original array a again, guiding the elements with values that greater than the newly placed element (the 5) into the last part of the new larger second array named b. The contents of the new array b would then be displayed back in the main function.  That's the logic I would like to see if it could work, but I can't juggle pointers. I just need to see this one in action. If I could see this work it would really help me wrap my head around the relationship between array names and pointers that use *p++ style of coding in C. Many, many thanks for reading this far and to the ones who can offer help. I would greatly appreciate it.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I have a question about programming in C(89) C.

Could someone please show me how to make a program that uses a custom function that rearranges array elements from one array of size n into a new larger second array of size (n+1) and places a new element into the new second larger array at a particular index location?

For example, the user would be prompted for a size like say, 7. Then the user would be prompted for the seven array element values, which could be like {1, 7, 4, 6, 3, 9, 8}.

Then the user gets prompted again for a new element value to add to the new larger second array. Let's say the new value is entered as 5. All of this would be done in main and no pointers are required.

Then main calls a custom function called rearrange. the prototype for rearrange must be;

void rearrange(int *a, int n, int insert, int *b);
 
After rearrange is done, main would display the contents of the new larger second array like so;  

{1, 4, 3, 5, 7, 9, 8}

Here's the trick though. Please notice how all the numbers lower than the new element 5 are still in
the same order as the first array and that all the elements with values higher than 5 are in the same order as the original array.

Here are my feelings about the logic of the custom function rearrange.

I feel like a counter variable counts the number of elements lower than the new value (say 5) so that the new value (5) can be placed at the correct index location (3) in the new array named b.

I think that a while loop with a conditional if could be used with a pointer to guide the elements of the first array a that are less than or equal to the new value (the 5) into the new larger second array named b.

And finally, another while loop with a conditional if walks through the original array a again, guiding the elements with values that greater than the newly placed element (the 5) into the last part of the new larger second array named b.

The contents of the new array b would then be displayed back in the main function. 

That's the logic I would like to see if it could work, but I can't juggle pointers. I just need to see this one in action. If I could see this work it would really help me wrap my head around the relationship between array names and pointers that use *p++ style of coding in C.

Many, many thanks for reading this far and to the ones who can offer help. I would greatly appreciate it.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education