Last active
August 29, 2015 14:01
-
-
Save xujiamin1216/919581f3af5e84608d2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class LinkedSet<T> | |
where T : LinkedSetElement | |
{ | |
private LinkedSetLinker<T> _top; | |
private LinkedSetLinker<T> _bottom; | |
public void Add(T elem) | |
{ | |
LinkedSetLinker<T> linker = new LinkedSetLinker<T>(elem); | |
linker.Next = _top; | |
_top = linker; | |
if (_bottom == null) | |
{ | |
_bottom = _top; | |
} | |
} | |
public T RemoveOne() | |
{ | |
LinkedSetLinker<T> top = _top; | |
_top = top.Next; | |
if (_top == null) { | |
_bottom = null; | |
} | |
if (top != null) | |
{ | |
return top.Self; | |
} | |
else | |
{ | |
return null; | |
} | |
} | |
public bool IsEmpty() | |
{ | |
return _top == null; | |
} | |
public bool Contains(T elem) { | |
return elem.Count != 0; | |
} | |
} |
This file contains hidden or 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
public abstract class LinkedSetElement | |
{ | |
private int _Count = 0; | |
public void Added() | |
{ | |
_Count++; | |
} | |
public void Removed() | |
{ | |
_Count--; | |
} | |
public int Count | |
{ | |
get | |
{ | |
return _Count; | |
} | |
} | |
} |
This file contains hidden or 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
class LinkedSetLinker<T> | |
where T : LinkedSetElement | |
{ | |
public LinkedSetLinker(T elem) | |
{ | |
_Self = elem; | |
elem.Added(); | |
} | |
private T _Self; | |
public T Self | |
{ | |
get { | |
_Self.Removed(); | |
return _Self; | |
} | |
} | |
public LinkedSetLinker<T> Next { get; set; } | |
} |
This file contains hidden or 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
来答题的原因有两个: | |
1. 我上周开始学C#了; | |
2. 你说你的题没人答,我就来了; | |
有奖征答的那道题,我不会,等你的答案吧; | |
希望这次不是无厘头; | |
如果题答得太烂了会耽误你的时间的话,告诉我一声,我晚些再过来答; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment