public override void Write(IWordNode w) { if (IsOpen) { streamWriter.WriteLine(w.Word); _numwrites++; } else { throw new InvalidOperationException("Error: Stream is Closed"); } }
public override bool isStepAway(IWordNode nod) { // Trivial Rejections // if either string is empty then they are not one step away if (nod.Word == "" || Word == "") { return(false); } // If words are equal then they are not 1 step away if (this.Word.Equals(nod.Word)) { return(false); } // if words differ in length the they cannot be one step away if (nod.Word.Length != this.Word.Length) { return(false); } // ---------------------------------------------------- // Take to char array to access character sequence of strings char[] nodarray = nod.Word.ToCharArray(); char[] thisarray = this.Word.ToCharArray(); // loop through to calculate number of differences int difs = 0; for (int i = 0; i < this.Word.Length; i++) { if (nodarray[i] != thisarray[i]) { difs++; } } // function returns true iff a single difference otherwise false if (difs == 1) { return(true); } else { return(false); } }
/// <summary> /// Primary String comparison function /// </summary> /// <param name="node">word to be compared against</param> /// <returns>return true iff there is only a single step difference </returns> public abstract bool isStepAway(IWordNode node);
public abstract bool Contains(IWordNode node);
public abstract void Append(IWordNode node);
/// <summary> /// WordWriter Writes Words one at a time to stream /// </summary> public abstract void Write(IWordNode w);