Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
expand button
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
Check Mark
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;
        }


       



Knowledge Booster
Background pattern image
Computer Science
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.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education