Skip to content

Commit 6c729b6

Browse files
committed
feat: Merge two ArrayLists by pattern List1 + List2 + List1 and print result
🧠 Logic: - Accepts sizes and elements of two lists from user input. - Stores elements in `list1` and `list2` using `ArrayList<Integer>`. - Creates a `mergedList` and adds: - All elements of `list1` - Then all elements of `list2` - Then `list1` again to form the final merged pattern. - Prints the merged list in a single line. Signed-off-by: Somesh diwan <[email protected]>
1 parent d818eda commit 6c729b6

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

Section9ArrayAB/Array IMP/MergeTwoLists.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*Logic to Merge Lists
2-
Input:
3-
4-
Read the sizes of List 1 (N) and List 2 (X).
5-
Read the elements of List 1 and List 2.
6-
7-
Merge:
8-
Create a new list (mergedList).
9-
Add all elements of List 1 to mergedList.
10-
Add all elements of List 2 to mergedList.
11-
Add all elements of List 1 again to mergedList.
12-
Output:
13-
14-
Print the elements of mergedList.
15-
16-
*/
171
import java.util.ArrayList;
182
import java.util.Scanner;
193

@@ -49,6 +33,7 @@ public static void main(String[] args) {
4933
}
5034
}
5135
}
36+
5237
/*
5338
Key Steps
5439
Input:
@@ -59,3 +44,19 @@ Use addAll() to combine the lists in the required order.
5944
Iterate through mergedList and print the elements.
6045
This logic works for any size of N and X.
6146
*/
47+
48+
/*
49+
Logic to Merge Lists
50+
Input:
51+
Read the sizes of List 1 (N) and List 2 (X).
52+
Read the elements of List 1 and List 2.
53+
54+
Merge:
55+
Create a new list (mergedList).
56+
Add all elements of List 1 to mergedList.
57+
Add all elements of List 2 to mergedList.
58+
Add all elements of List 1 again to mergedList.
59+
60+
Output:
61+
Print the elements of mergedList.
62+
*/

0 commit comments

Comments
 (0)