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
If Log2 x - 5 Log x + 6 = 0, then what would the value / values of x be?
What Is Kyc?
debentures book building
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?
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.
A beats B by 10 meters and B beats C by 15 metres the A beats C by
(1/2) of a number is 3 times more than the (1/6) of the same number?
If a square is formed by the diagonal of the square as an edge, what is the ratio between the area?
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?
Find the next three terms of the series; 1, 4, 9, 18, 35 - - - - -
Scientific publishing aptitude interview question
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.
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?
Find the next series: SE QU EN TI ?
The number 0.05 is what percent of 20?