Thread: Defining an Array

  1. #1

    Question Defining an Array

    I am writing a merge-sort algorithm program for school. The pseudo-code says that I have to create an array 'L' and array 'R' with a size that is determined by calculations done with some array indices.

    I could basically hard-code in some large arrays.

    However, is there a way of doing the calculations and then inputing the result into the array declaration...

    //example of function
    MERGE(A,p,q,r)/*where A is array, p is first indice, q is lower bound mid-point, and r id last indice*/
    n1 = q - p + 1;
    n2 = r - q;
    int L[n1];
    int R[n2];

  2. #2
    Join Date
    Aug 2001
    Groningen (NL)
    You could do something like this:

    n1 = q - p + 1; 
    n2 = r - q; 
    int *L = new int [n1]; 
    int *R = new int [n2];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem defining an array :s
    By Matty_Alan in forum C Programming
    Replies: 2
    Last Post: 12-23-2008, 11:16 AM
  2. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  3. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM