Can i know how to increase the bound of the array so that the value 512000 and 1000000 can run. Can you pls show me the code?

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

#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;

void merge(int arr[], int l, int m, int r)
{
    int n1 = m - l + 1;
    int n2 = r - m;
    int L[n1], R[n2];
    for (int i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (int j = 0; j < n2; j++)
        R[j] = arr[m + 1 + j];
    int i = 0;
    int j = 0;
    int k = l;

while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        }
        else {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int arr[],int l,int r){
    if(l>=r){
        return;
    }
    int m =l+ (r-l)/2;
    mergeSort(arr,l,m);
    mergeSort(arr,m+1,r);
    merge(arr,l,m,r);
}


int main()
{
    srand(time(0));
    long int n;
    cout<<"Enter the number of orders ";
    cin>>n;
    int ids[n],cost[n],sorted_ids[n],sorted_cost[n];
    for(int i=0;i<n;i++)
    {
        ids[i]=rand();
    }
    for(int i=0;i<n;i++)
    {
        cost[i]=rand();
    }
    while(1)
    {
        cout<<"1. Unsorted Order ids and their cost"<<endl;
        cout<<"2. Sorted Order ids and their cost"<<endl;
        cout<<"3. exit"<<endl;
        int choice;
        cin>>choice;
        if(choice == 1)
        {
            cout<<"Order ID\t Cost"<<endl;
            for(int i=0;i<n;i++)
            {
                cout<<"FD"<<ids[i]<<"\t\t RM"<<cost[i]<<endl;
            }
        }
        else if(choice==2)
        {
            for(int i=0;i<n;i++)
            {
                sorted_ids[i]=ids[i];
            }
            time_t start,end;
            time(&start);
            mergeSort(sorted_ids,0,n);
            for(int i=0;i<n;i++)
            {
                int j;
                for(j=0;j<n;j++)
                {
                    if(ids[j]==sorted_ids[i])
                    {
                        sorted_cost[i]=cost[j];
                        break;
                    }
                }
            }
            time(&end);
            double time_taken = double(end-start);
            cout<<"Time taken to mergesort is "<<time_taken<<" sec"<<endl;
            cout<<"Order ID\t Cost"<<endl;
            for(int i=0;i<n;i++)
            {
                cout<<"FD"<<sorted_ids[i]<<"\t\t RM"<<sorted_cost[i]<<endl;
            }
        }
        else if(choice==3)
        {
            break;
        }
        else
        {
            cout<<"Invalid choice"<<endl;
        }
    }
}

I cannot run the program with n=512000 and n=1000000. Can i know how to increase the bound of the array so that the value 512000 and 1000000 can run. Can you pls show me the code? 

Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Linked List Representation
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