(Написать код на C#) Отсортировать элементы множества А по возрастанию, а элементы множества В по убыванию.

Ответы

Ответ дал: MaxLevs
1

Код:

  • using System;
  • using System.Collections;
  • using System.Collections.Generic;
  • namespace HowOldAreYou
  • {
  •    class Program
  •    {
  •        static void Main(string[] args)
  •        {
  •            var A = new List<int> {6, 4, 2, 1, 4, 3};
  •            var B = new List<int> {7, 3, 3, 2, 3, 4};
  •            
  •            Console.Write("A: "); PrintVector(A);
  •            Console.Write("B: "); PrintVector(B);
  •            
  •            A.Sort((a, b) => a > b ? 1 : a < b ? -1 : 0);
  •            B.Sort((a, b) => a < b ? 1 : a > b ? -1 : 0);
  •            Console.Write("New A: "); PrintVector(A);
  •            Console.Write("New B: "); PrintVector(B);
  •        }
  •        static void PrintVector(IEnumerable vector)
  •        {
  •            foreach (var element in vector)
  •            {
  •                Console.Write(element);
  •                Console.Write(" ");
  •            }
  •            Console.WriteLine();
  •        }
  •    }
  • }
Приложения:
Вас заинтересует