Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 19: Inserting Array Elements in Ascending Order Folder name: A170 E19 Your astName YourFirstName Complete the project Insertlnorder so that the user can enter

image text in transcribed
image text in transcribed
Exercise 19: Inserting Array Elements in Ascending Order Folder name: A170 E19 Your astName YourFirstName Complete the project Insertlnorder so that the user can enter positive integers to be stored in ascending order in an array of capacity 5. The project already contains code to declare an array and insert the first number. Once the first number is inserted awhile loop start to iterate until the array is full. The loop willinsert the elements in the array and print the array after each insertion. Once the array is full, a message will be displayed to end the program. Your job is to complete the while loop. Pseudocode Ask the user which number to insertand store the number in a IF the number to insert is larger than the last number in the array Insert the number at the end of the array and increment the number of elements. ELSE//start traversing the array tofind where to insert the number WHILE the location is not found and the end of the array has not been reached IF the number to insert is smaller or equal the element at this index Use a FOR loop to shift elements Insert the element Increment number of elements Move forward How do you insert an element in the array? o You shift elements to the left to "make space for the new number. Example: If you want to insert 34, you should insert it at index 2. Starting from the end of the list, shift each element to its right. 1 3 5 6 7 8 9 11 24 43 51 63 74 84 0 0 0 Overwrite element at index 2 with element to insert, 11 24 34 43 51 63 74 84 0 To Number to insert: 5 Array is now: 5 Number to inserti 2 o Test your program by inserting: Array is now: 2 5 A number smaller than the first element Example output Number to insert 1 7 Anumber larger than the last element Array is now: 2 5 7 Number to insert: 4 A number in between the first and last element Array is now 2 4 5 7 Anumber already in the array Number to insert Array is now 2 4 5 5 7 Array is full

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

Students also viewed these Databases questions