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

Answers were Sorted based on User's Feedback



There are two sorted arrays a1 and a2 of size n1 and size n2 respectively. array a1 is full array..

Answer / 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

There are two sorted arrays a1 and a2 of size n1 and size n2 respectively. array a1 is full array..

Answer / surjeet gangwar

import java.util.*;
class arrtest
{
int[][] a=new int[3][3];
int[][] b={{1,1,1},{1,1,1},{1,1,1}};

public arrtest()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the matrix:\n");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
a[i][j]=sc.nextInt();
}

void oper()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
if(a[i][j]==0)
for(int k=0;k<3;k++)
{
b[i][k]=0;
b[k][j]=0;
}
}

void print()
{
System.out.println(" the matrix:\n");
for(int i=0;i<3;i++)
{ for(int j=0;j<3;j++)
System.out.print("\t"+b[i][j]);

System.out.println("\n");
}
}
}
class arrdemo
{
public static void main(String a[])
{
arrtest at=new arrtest();
at.oper();
at.print();
}
}

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More General Aptitude Interview Questions

A car wash can wash 8 cars in 18 minutes,At this rate, how many cars can the car wash wash in 3 hours?

1 Answers   Wipro,


There are 3 societies A, B, C.A lent cars to B and C as many as they had already.After some time B gave as many tractors to A and C as many as they have. After sometime c did the same thing. At the end of this transaction each one of them had 24.Find the cars each originally had.

0 Answers   Infosys,


In a square, all the mid points are joined. The inner square is shaded.If the area of the square is A, what is the area of the shaded area?

0 Answers   IBM,


Dear Sir, Can u send the andhra bank model question with answers to my Email ID

0 Answers   Andhra Bank,


A store owner decided to raise the price of a particular item by exactly 10%. Of the following which is NOT the new price?

0 Answers   CTS,






There are 6 people W,H,M,C,G,F who are murderer , victim , judge , police, witness, hangman. There was no eye witness only circumtancial witness. The murderer was sentenced to death. Read following statement and determine who is who. 1. M knew both murderer and victim. 2. Judge asked C to discribe murder incident. 3. W was last to see F alive. 4. Police found G at the murder site. 5. H and W never met.

10 Answers   Cognizant,


What is Derivative and different types of Derivatives? Difference between Call and Put Option?

4 Answers   eClerx,


In a well of 20feet depth, a frog jumps 5feet up in the morning and comes 4feet down in the evening, on which day the frog gets out of the well.

0 Answers   Accenture,


Mohan started running from point A along with a circle of 1400 meter radius with the speed of 12 Km/hr. Ram also started running in the opposite direction from the same point with the speed of 15 km/hr. Both started at 9:00 AM. At what time will they meet first time? 9:15 AM 9:25 AM 10:00 AM 9:20 AM None of the Above

2 Answers  


The Longest River in the World____________

11 Answers  


there was a swimming pool of squre shape and it is having four trees at four ends....how to double the size of swimming pool without cutting the trees...?

7 Answers   Infosys,


Which of the following does multithreading allow? A. several transactions that require the same program to use one copy of the program. B. many tasks to be allocated to the terminal. C. an audit trail of all files records from all files updated by a particular application

0 Answers  


Categories