CSharp · Console
using System;
using System.Collections.Generic;
Test(new List<int>(){ 2 });
Test(new List<int>(){});
Test(new List<int>(){ 2, 3 });
Test(new List<int>(){ 1, 2, 2, 1 });
Test(new List<int>(){ 1, 2, 3, 2, 1 });
Test(new List<int>(){ 1, 3, 3, 2, 1 });
static void Test<T>(List<T> lst) where T : IEquatable<T>
{
Console.Write($"EstPalindrome : {EstPalindrome(lst)} pour la séquence : ");
Afficher(lst);
}
static void Afficher<T>(IEnumerable<T> elems)
{
foreach(T e in elems)
Console.Write($"{e} ");
Console.WriteLine();
}
static bool EstPalindrome<T>(List<T> lst) where T : IEquatable<T>
{
int milieu = lst.Count / 2;
for(int i = 0; i < milieu; ++i)
if(!lst[i].Equals(lst[lst.Count - i - 1]))
return false;
return true;
}