Complete the code to perform a sort on the array using built-in methods.
Array.Sort(arr, (a, b) => (a.Value [1] b.Value) ? -1 : (b.Value [1] a.Value) ? 1 : 0);
The comparison uses < to sort in ascending order.
Complete the code to check if a sorting algorithm is stable by comparing original and sorted lists.
bool isStable = originalList.SequenceEqual(sortedList, [1]);EqualityComparer<Item>.Default checks value equality, which helps verify stability.
Fix the error in the code to perform a stable sort using LINQ.
var stableSorted = list.OrderBy(x => x.Key).[1]();OrderBy returns an IEnumerable; ToList() converts it back to a list preserving order.
Fill both blanks to create a stable sort by two keys using LINQ.
var sorted = list.OrderBy(x => x.[1]).[2](x => x.Age).ToList();
OrderBy sorts by Name first, ThenBy sorts by Age next, preserving stability.
Fill all three blanks to implement a custom stable sort using List.Sort with a comparer.
list.Sort((x, y) => {
int result = x.[1].CompareTo(y.[2]);
if (result == 0) return x.[3].CompareTo(y.[3]);
return result;
});Compare first by Name, then by Age if Names are equal to keep sort stable.
