Изучите следующий код:
public class List<T> : IEnumerable<T> { T[] collection = new T[100]; int count = 0; public void Add(T value) { if (count == collection.Length) { var enlargedCollection = new T[count * 2]; Array.Copy(collection, enlargedCollection, collection.Length); collection = enlargedCollection; } collection[count++] = value; } public T this[int index] { get { return collection[index]; } set { collection[index] = value; } } public bool Contains(T value) { for (int i = 0; i < count; i++) if (collection[i].Equals(value)) return true; return false; } }
1. Что вы можете сказать об этом коде?
1 балл
Сложность операции Add всегда
\Theta(1)
Сложность операции доступа к элементу по индексу
\Theta(1)
Сложность операции Contains
\Theta(n)
×
Практика, практика и еще раз практика!
Войдите
или
зарегистрируйтесь
, чтобы отвечать на тесты и решать задачи.