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

2 is what % of 4t ?

765


A person meets a train at a railway station coming daily at a particular time . One day he is late by 25 minutes, and he meets the train 5 k.m. before the station. If his speed is 12 kmph, what is the speed of the train.

1036


There were 36 chairs. how many ways can they be placed such that all rows have equal no. of chairs and atleast three chairs are there in each row and there are atleast three rows.

880


If PQRST is a paralellogram .What is the ratio triangle PQS & PQRST.

719


A car is traveling at a uniform speed. The driver sees a milestone showing a 2-digit number. After traveling for an hour the driver sees another milestone with the same digits in reverse order. After another hour the driver sees another milestone containing the same two digits. What is the average speed of the driver.

721






If the total distance of a journey is 120 km .If one goes by 60 kmph and comes back at 40kmph what is the average speed during the journey?

709


find 70.56/ 11.2 =?

985


Perimeter of the back whell = 9 feet, front wheel = 7 feet on a certain distance the front wheel gets 10 revolutions more than back wheel . what is the distance?

862


What is the probability of getting 3 or 4 in 3 consecutive rolls of a dice ?

1821


A sales person multiplied by a number and get the answer 3. Instead of that number divided by 3. What is the answer she actually has to get. (1/3) * 1 *3 =3 so the no= 1 divided by three.

704


What would be the simple interest obtained on an amount of Rs. 5580 at the rate of 6.5 % p.a. after 5 years?

1374


3 angles or 3 sides r given. Which will form a triangle?

659


Find the Next Series Nuumber 21, 463, 687, 238, 1134, ----

855


There's a camel living in a desert. There is a market 1000 miles away. The camel has 3000 dates for sale. It has to take the date to the market. But for that hte camel eats one date per mile. How many dates the camel can trade?

818


A person with some money spends1/3 for cloths, 1/5 of the remaining for food and 1/4 of the remaining for travel. He is left with Rs 100/- . How much did he have with him in the beginning ?

855