logo CodeStepByStep logo

Mystery1

Language/Type: C# List List mystery collections

Write the output produced by the method below when passed each of the following Lists:

public static void Mystery1(List a)
{
    for (int i = a.Count - 1; i > 0; i--)
    {
        if (a[i] < a[i - 1])
        {
            int n = a[i]; 
            a.RemoveAt(i); 
            a.Insert(0, n); 
        } 
    } 
    Console.WriteLine(a); 
} 
[2, 6, 1, 8]
[10, 30, 40, 20, 60, 50]
[-4, 16, 9, 1, 64, 25, 36, 4, 49]

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.