Sha256: b35cc51a860169afe5a0b009a18751808a570df7172530a6f91a711ffaa42ec8

Contents?: true

Size: 1.92 KB

Versions: 115

Compression:

Stored size: 1.92 KB

Contents

using System.Collections.Generic;

public class School
{
    public IDictionary<int, IList<string>> Roster { get; private set; }

    public School()
    {
        Roster = new Dictionary<int, IList<string>>();
    }

    public void Add(string student, int grade)
    {
        if (Roster.ContainsKey(grade))
            Roster[grade].Add(student);
        else
            Roster.Add(grade, new SortedList<string> { student });
    }

    public IList<string> Grade(int grade)
    {
        IList<string> students;
        if (Roster.TryGetValue(grade, out students))
            return students;
        return new List<string>(0);
    }
}

public class SortedList<T> : IList<T>
{
    private readonly List<T> list = new List<T>();

    public int IndexOf(T item)
    {
        return list.IndexOf(item);
    }

    public void Insert(int index, T item)
    {
        throw new System.NotSupportedException("Insert would ruin sort");
    }

    public void RemoveAt(int index)
    {
        list.RemoveAt(index);
    }

    public T this[int index]
    {
        get { return list[index]; }
        set
        {
            list.RemoveAt(index);
            Add(value);
        }
    }

    public void Add(T item)
    {
        list.Insert(~list.BinarySearch(item), item);
    }

    public void Clear()
    {
        list.Clear();
    }

    public bool Contains(T item)
    {
        return list.Contains(item);
    }

    public void CopyTo(T[] array, int arrayIndex)
    {
        list.CopyTo(array, arrayIndex);
    }

    public int Count
    {
        get { return list.Count; }
    }

    public bool IsReadOnly
    {
        get { return false; }
    }

    public bool Remove(T item)
    {
        return list.Remove(item);
    }

    public IEnumerator<T> GetEnumerator()
    {
        return list.GetEnumerator();
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return list.GetEnumerator();
    }
}

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
trackler-2.0.8.14 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.13 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.12 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.11 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.10 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.9 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.8 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.7 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.6 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.5 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.4 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.3 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.2 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.8.1 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.7.0 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.6.44 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.6.43 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.6.42 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.6.41 tracks/csharp/exercises/grade-school/Example.cs
trackler-2.0.6.40 tracks/csharp/exercises/grade-school/Example.cs