There are two sorted arrays
a1 and a2 of size n1 and size n2 respectively.
array a1 is full
array a2 has exactly n1(size of array a1) empty space.
example
a1[]=1234
a2[]=56789_ _ _ _
Write a function to merge these two arrays to form a sorted
array without any extra memory use.

i want a solution in c/c++ language

Answer Posted / ajay

class A
{
public static void main(String args[])
{
int[] a1={1,2,3,4};
int[] a2=new int[9];

a2[0]=5; a2[1]=6; a2[2]=7; a2[3]=8; a2[4]=9;

for(int i=8;i>=4;i--)
a2[i]=a2[i-4];

for(int i=0;i<=3;i++)
a2[i]=a1[i];


for(int i=0;i<=8;i++)
System.out.println(a2[i]);

}
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If Log2 x - 5 Log x + 6 = 0, then what would the value / values of x be?

787


What Is Kyc?

783


debentures book building

1734


A piece of cloth costs Rs 35. If the piece were 4m longer and each meter costs Re 1.00 less, the cost would remain unchanged. How long is the piece?

854


9 cards are there. you have to arrange them in a 3*3 matrix. cards are of 4 colours.they are red,yellow,blue,green. conditions for arrangement: one red card must be in first row or second row.2 green cards should be in 3rd column.Yellow cards must be in the 3 corners only. Two blue cards must be in the 2nd row. At least one green card in each row.

732






A beats B by 10 meters and B beats C by 15 metres the A beats C by

702


(1/2) of a number is 3 times more than the (1/6) of the same number?

819


If a square is formed by the diagonal of the square as an edge, what is the ratio between the area?

1027


What would be the simple interest obtained on an amount of Rs. 3460 at the rate of 8.5 per cent per annum after 6 years?

1396


Find the next three terms of the series; 1, 4, 9, 18, 35 - - - - -

765


Scientific publishing aptitude interview question

991


it has 20 mixutre conatins mil and water in the ratio 3:5,replace 4 litres of mixture with 4 litres of water what is the final ratio of milk and water.

892


In 3.5 Kg rod , there is 74% silver. If it is alloyed with a 0.5 Kg rod, the % of silver goes up to 84%. The percent of silver in 0.5 Kg rod?

1006


Find the next series: SE QU EN TI ?

850


The number 0.05 is what percent of 20?

814