Skip to content

Instantly share code, notes, and snippets.

@xujiamin1216
Created May 27, 2014 02:01
Show Gist options
  • Save xujiamin1216/ca3b66980c20ee9823c4 to your computer and use it in GitHub Desktop.
Save xujiamin1216/ca3b66980c20ee9823c4 to your computer and use it in GitHub Desktop.
// 希望这个会好点,但是Contains的时间复杂度高了
class LinkedSet<T>
where T : class
{
private List<T> _set = new List<T>();
public void Add(T elem)
{
_set.Add(elem);
}
public T RemoveOne()
{
T result = null;
if (_set.Count > 0)
{
result = _set.ElementAt(_set.Count - 1);
_set.RemoveAt(_set.Count - 1);
}
return result;
}
public bool IsEmpty()
{
return _set.Count == 0;
}
public bool Contains(T elem)
{
return _set.Contains(elem);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment