Skip to content

Instantly share code, notes, and snippets.

@audinue
Created August 11, 2017 20:36
Show Gist options
  • Save audinue/a133965ca2bfbf2ebcf2a44e7db9dac7 to your computer and use it in GitHub Desktop.
Save audinue/a133965ca2bfbf2ebcf2a44e7db9dac7 to your computer and use it in GitHub Desktop.
class Orderable : IOrderable
{
private int order;
private string name;
public Orderable(int order, string name)
{
this.order = order;
this.name = name;
}
public int Order
{
get
{
return order;
}
}
public string Name
{
get
{
return name;
}
}
}
interface IOrderable
{
int Order { get; }
}
sealed class Ordering<T>
where T : IOrderable
{
private readonly List<T> list;
private int last;
public Ordering(List<T> list)
{
this.list = list;
}
public void Add(T item)
{
if (list.Count == 0)
{
list.Add(item);
last = item.Order;
return;
}
if (last == item.Order)
{
list.Add(item);
return;
}
if (last < item.Order)
{
list.Add(item);
last = item.Order;
return;
}
for (int i = 0; i < list.Count; i++)
{
if (list[i].Order > item.Order)
{
list.Insert(i, item);
break;
}
}
}
}
interface IIndexable
{
string Id { get; }
}
sealed class Indexing
{
public IIndexable Get(string id)
{
throw new NotImplementedException();
}
public void Add(IIndexable indexable)
{
}
public void Remove(IIndexable indexable)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment