Question: Please Convert this Java Code to C/C++ Code using NetBeans : Code : package chegg; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class MergingList {
Please Convert this Java Code to C/C++ Code using NetBeans :
Code :
package chegg;
import java.util.ArrayList; import java.util.Collections; import java.util.List;
public class MergingList {
public static void main(String[] args) {
//Creating List and adding the items
List
List
//Sorting the above lists Collections.sort(l1); Collections.sort(l2);
// Program to merge both the sorted list //Creating the empty merged list List
//initializing the iterators int i = 0, j = 0;
while (i < l1.size() && j < l2.size()) {
// we will compare the elements of both list if the element of the i-th position in list //is greater than element of j-th position in the second list //then we will add the i-th element of the first list in the merged list //else we will put the the j-th element of the second list into the first list if (l1.get(i) < l2.get(j)) { mergedList.add(l1.get(i)); i++;
} else { mergedList.add(l2.get(j)); j++; } }
//now we will add the leftover items of the first list into the merged list while (i < l1.size()) { mergedList.add(l1.get(i)); i++; } //now we will add the leftover items of the second list into the merged list
while (j < l2.size()) { mergedList.add(l2.get(j)); j++; }
//Printing the merged list System.out.println(mergedList.toString()); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
