using System; using System.Diagnostics; namespace SpaceInvaders { public class SLinkIterator : Iterator { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- public Node pHead; public Node pCurr; public bool isDone; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public SLinkIterator() : base() { this.Clear(); } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public void Reset(SLink pHead) { if(pHead != null) { this.isDone = false; this.pCurr = pHead; this.pHead = pHead; } else { this.Clear(); } } public override Node First() { if(this.pHead != null) { this.isDone = false; this.pCurr = this.pHead; } else { this.Clear(); } return pCurr; } public override Node Next() { SLink pLink = (SLink)this.pCurr; if (pLink != null) { pLink = pLink.pNext; } this.pCurr = pLink; if (pLink == null) { isDone = true; } else { isDone = false; } return pLink; } //returns current node public override Node Peek() { Node pNode = this.pCurr; return pNode; } public override bool IsDone() { return isDone; } //------------------------------------------------------------------- // PRIVATE METHODS //------------------------------------------------------------------- private void Clear() { this.pHead = null; this.pCurr = null; this.isDone = true; } } //end class } //end namespace