Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

"How will you merge these two arrays? Write the program
Array: A 1 18 22 43
Array: B 3 4 6 20 34 46 55
Output Array: C 1 3 4 6 18 20 22 34 43 46 55"

Answer Posted / naman patidar

public class MargeSort {
public static void main(String[] args) {
int a[] = { 2, 5, 7, 9, 10, 15 };
int b[] = { 1, 3, 4, 5, 12, 14 };
int c[] = new int[a.length + b.length];
int aIndex = 0, bIndex = 0, cIndex = 0;

while (aIndex < a.length && bIndex < b.length) {
if (a[aIndex] < b[bIndex]) {
c[cIndex++] = a[aIndex++];
} else {
c[cIndex++] = b[bIndex++];
}
}

while (aIndex < a.length) {
c[cIndex++] = a[aIndex++];
}
while (bIndex < b.length) {
c[cIndex++] = b[bIndex++];
}
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
}
}

Is This Answer Correct ?    7 Yes 14 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which header file allows file i/o with streams a) fileio.h b) iostream.h c) fstream.h

1070


Is c++ low level?

991


Is c the same as c++?

952


What is a base class?

1046


Why c++ is the best language?

1005


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

2466


How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?

983


what do you mean by volatile variable?

979


What are the manipulators in c++?

980


What do you mean by overhead in c++?

1026


What it is and how it might be called (2 methods).

1092


How can we read/write Structures from/to data files?

1063


Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

1877


Write a struct time where integer m, h, s are its members?

915


What is the difference between #import and #include?

987