using System.Collections.Generic;
using System.Linq;
public class MyCollection<T>
{
private readonly List<T> items = new List<T>();
public IReadOnlyList<T> All => items;
public void Add(T item)
{
items.Add(item);
}
public void Remove(T item)
{
items.Remove(item);
}
public T Pop()
{
var item = items.Last();
Remove(item);
return item;
}
public void Push(T item)
{
items.Add(item);
}
public T Shift()
{
var item = items.First();
Remove(item);
return item;
}
public void Unshift(T item)
{
items.Insert(0, item);
}
public void Insert(int index, T item)
{
items.Insert(index, item);
}
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme