Created
May 27, 2014 02:01
-
-
Save xujiamin1216/ca3b66980c20ee9823c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 希望这个会好点,但是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