Page 334 - Computer science 868 Class 12
P. 334

C.  Answer the following questions:
                  1.  The following function is a part of some class. It sorts the array a[] in ascending order using the insertion sort technique. There
                    are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which must be replaced by some expressions/statements so that
                    the function works correctly.
                    void insertsort (int a [])
                    {
                    int m = ?1?;
                    int b, i, t;
                    for (i = ?2? ; i < m; i++)
                    {
                    t = a[i];
                    b = i - 1;
                    while (?3? > = 0 && t < a [ b ])
                    {
                    a[b+1] = a[b];
                    ?4?;
                    }
                    ?5? = t;
                    }
                    }
                     (i)   What is the expression or statement at ?1?
                    (ii)   What is the expression or statement at ?2?
                     (iii)  What is the expression or statement at ?3?
                     (iv)   What is the expression or statement at ?4?
                    (v)   What is the expression or statement at ?5?
                  2.  The following function is a part of some class that computes and sorts an array arr [] in ascending order using the bubble sort
                    technique. There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which must be replaced by some statements/
                    expressions so that the function works properly.
                    void bubblesort (int arr [])
                    {
                    int i. j, k temp;
                    for (i = 0; ?1?; i ++)
                    {
                    for (j = 0; ?2?;j++)
                    {
                    arr[j] > ?3?)
                    {
                    temp = arr [j];
                    ?4? = arr [j + 1];
                    arr [j + 1] = ?5?;
                    }
                    }
                    }
                    }
                     (i)   What is the expression or statement at ?1?
                    (ii)   What is the expression or statement at ?2?
                     (iii)  What is the expression or statement at ?3?
                     (iv)   What is the expression or statement at ?4?
                    (v)   What is the expression or statement at ?5?
                  3.  What will be the values stored in ar[] after the following program is executed?
                      public static void main(String args[])
                     {
                     int i,j=1;
                     int dividend=2,N=30;
                     int ar[]={2,0,0,0,0,0,0,0,0,0};


                332332  Touchpad Computer Science-XII
   329   330   331   332   333   334   335   336   337   338   339