Askor

NewHw28

Apr 15th, 2022
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         List<int> list1 = new List<int> { 1, 5, 3, 7, 6, 8 };
  9.         List<int> list2 = new List<int> { 2, 4, 3, 8 };
  10.  
  11.         List<int> targetList = UniteLists(list1, list2);
  12.  
  13.         foreach (var item in targetList)
  14.         {
  15.             Console.Write($"{item}, ");
  16.         }
  17.  
  18.         Console.ReadKey();
  19.     }
  20.  
  21.     static List<int> UniteLists(List<int> list, List<int> subList)
  22.     {
  23.         List<int> targetList = new List<int>();
  24.  
  25.         for (int i = 0; i < list.Count; i++)
  26.         {
  27.             for (int j = 0; j < subList.Count; j++)
  28.             {
  29.                 if(list[i] == subList[j])
  30.                 {
  31.                     subList.Remove(subList[j]);
  32.                 }
  33.             }
  34.         }
  35.  
  36.         list.AddRange(subList);
  37.  
  38.         targetList = list;
  39.         targetList.Sort();
  40.  
  41.         return targetList;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment