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