CSharp · Console
using System;
using System.Collections.Generic;
Test(new List<int>());
Test(new List<int>(){ 3 });
Test(new List<int>(){ 1, 2, 3, 4 });
Test(new List<int>(){ 2, 6, 4 });
Test(new List<int>(){ 1, 3, 5, 7, 9 });
static void Test<T>(List<T> lst) where T : IComparable<T>
{
Console.Write(EstTrié(lst) ? "Séquence triée : " : "Séquence non triée : ");
Afficher(lst);
}
static void Afficher<T>(IEnumerable<T> elems)
{
foreach(T e in elems)
Console.Write($"{e} ");
Console.WriteLine();
}
static bool EstTrié<T>(List<T> lst) where T : IComparable<T>
{
for(int i = 1; i < lst.Count; ++i)
if(lst[i-1].CompareTo(lst[i]) > 0)
return false;
return true;
}