n program that inserts an element IT ar Array) for the following data. (Siz 1000,2000,5000,4000
![Q No.1: Write down program that inserts an element ITEM into the LOC (2nd position) in
LA (Linear Array) for the following data. (Size of the array is 5).
1000,2000,5000,4000](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3ced33f3-9784-42db-addd-1c9bdb632f18%2Ffd00c6fd-665f-4938-8cae-aed4a077e09d%2Fvjzl6xa_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Here is the documented code to solve this assignment:
chegg.cpp:
#include <iostream>
#define SIZE 10
void show(const int (&A)[SIZE],
const int N) {
for(int i = 0; i < N; ++i) {
std::cout << A[i] << ", ";
}
std::cout << "\b\b " << std::endl;
}
int Find_Location_To_Insert(const int (&A)[SIZE],
const int N,
int &K,
const int ITEM) {
int LB = 0, UB = N - 1;
for(K = LB; K <= UB; ++K) {
if(A[K] > ITEM) {
// insert at front or in middle
return K;
}
}
// insert at the end of array
return K;
}
void INSERT(int (&A)[SIZE],
int &N,
int K,
const int ITEM) {
// initialize counter
int J = N - 1;
while(J >= K) {
// move the Jth element downward
A[J + 1] = A[J];
// decrease counter
J = J - 1;
}
// insert element
A[K] = ITEM;
// reset N
N = N + 1;
}
int main() {
int A[SIZE];
int N = 0;
int ITEM;
int K;
while(true) {
show(A, N);
// overflow check
if(N == SIZE) {
std::cout << "Overflow, Array is Full." << std::endl;
break;
}
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)