Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- List<int> list1 = new List<int> { 1, 5, 3, 7, 6, 8 };
- List<int> list2 = new List<int> { 2, 4, 3, 8 };
- List<int> targetList = UniteLists(list1, list2);
- foreach (var item in targetList)
- {
- Console.Write($"{item}, ");
- }
- Console.ReadKey();
- }
- static List<int> UniteLists(List<int> list, List<int> subList)
- {
- List<int> targetList = new List<int>();
- for (int i = 0; i < list.Count; i++)
- {
- for (int j = 0; j < subList.Count; j++)
- {
- if(list[i] == subList[j])
- {
- subList.Remove(subList[j]);
- }
- }
- }
- list.AddRange(subList);
- targetList = list;
- targetList.Sort();
- return targetList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment