0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MyCollection

Posted at
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);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?