n program that inserts an element IT ar Array) for the following data. (Siz 1000,2000,5000,4000

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
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
Transcribed Image Text: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
Expert Solution
Step 1

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;
        }


       



steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
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