using System.Collections.Generic;
public static class Program
public static void Main()
string[] shapeTypes = {"circle", "triangle", "square" };
string[] shapeColor = { "red", "blue", "orange" };
double[] shapeArea = { 20, 5, 4 };
Sort(shapeArea, shapeTypes, shapeColor);
Console.WriteLine($"shapeTypes: {String.Join(", ", shapeTypes)}");
Console.WriteLine($"shapeColor: {String.Join(", ", shapeColor)}");
Console.WriteLine($"shapeArea: {String.Join(", ", shapeArea)}");
public static void Sort<TKey, T1, T2>(TKey[] keys, T1[] items1, T2[] items2,
IComparer<TKey> comparer = default)
ArgumentNullException.ThrowIfNull(keys);
ArgumentNullException.ThrowIfNull(items1);
ArgumentNullException.ThrowIfNull(items2);
if (items1.Length < keys.Length)
throw new ArgumentException("Array too small.", nameof(items1));
if (items2.Length < keys.Length)
throw new ArgumentException("Array too small.", nameof(items2));
comparer ??= Comparer<TKey>.Default;
int[] indices = new int[keys.Length];
for (int i = 0; i < indices.Length; i++) indices[i] = i;
Array.Sort<int>(indices, (x, y) => comparer.Compare(keys[x], keys[y]));
for (int i = 0; i < indices.Length - 1; i++)
while (k < i) k = indices[k];
static void Swap<T>(T[] array, int x, int y)