using System;
public class test
{ static void Main(string[] args)
{ int[] a = new int[] {}; int[] b = new int[] {};
a = new int[] { 1, 2, 3, 4 }; b = new int[] { 5, 6, 7, 8 }; Console.Write("El array '{0}' y '{1}' ", DisplayArray(a), DisplayArray(b)); if (sonIguales(a, b)) { Console.WriteLine("Son iguales"); } else { Console.WriteLine("No son iguales"); }
a = new int[] { 1, 2, 3, 4 }; b = new int[] { 1, 2, 3, 4 }; Console.Write("El array '{0}' y '{1}' ", DisplayArray(a), DisplayArray(b)); if (sonIguales(a, b)) { Console.WriteLine("Son iguales"); } else { Console.WriteLine("No son iguales"); }
a = new int[] { 1, 2, 3, 4 }; b = new int[] { 1, 3, 4, 2 }; Console.Write("El array '{0}' y '{1}' ", DisplayArray(a), DisplayArray(b)); if (sonIguales(a, b)) { Console.WriteLine("Son iguales"); } else { Console.WriteLine("No son iguales"); }
a = new int[] { 1, 2, 3, 4 }; b = new int[] { 1, 3, 4, 2 }; Console.Write("El array '{0}' y '{1}' ", DisplayArray(a), DisplayArray(b)); if (sonIguales(a, b, true)) { Console.WriteLine("Son iguales"); } else { Console.WriteLine("No son iguales"); }
}
static bool sonIguales(int[] a, int[] b, bool mismaPosicion=false)
{ if (a.Length != b.Length) { return false;
}
if (mismaPosicion == false) { Array.Sort(a);
Array.Sort(b);
}
for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) { return false;
}
}
return true;
}
static string DisplayArray(int[] arr) => string.Join(" ", arr);}
Comentarios sobre la versión: 1 (0)
No hay comentarios