/* * POSITION.java * * Created on March 24, 2008, 1:06 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package list_purge; /** * * @author suchenek */ //Copyright Dr. Marek A. Suchenek, 2005, 2006, 2007, 2008 - 2015 //All rights reserved // SLL implementation // POSITION is a list of the form (head, tail). // Definition of position of an element x in a list L: a subtail N of list L such that // x is the head of tail of N. (It exists for every element; in particular, use of the header // ensures the existence of first position.) // Definition of subtail of list L: Subtail of a list L is either L itself or // (if L is non-empty) a subtail of tail of L // Interpretation: Position always points to the previous element (for an extra level of // indirection), which is also needed to accomodate "end" position (next after last). // This makes the trailer (an element the represents the end position) superflous, but // requires introduction of an element (the header) that is pointed to by the first position. public class POSITION { public E head; public POSITION tail; public boolean isEqual(POSITION p) { return (this == p); // don't be deceived by the simplicity of this - it's not as obvious as it seems! } public boolean isValidPosition(LIST L) { if (this.isEqual(L.End())) return true; for (POSITION q = L.First(); q != L.End(); q = L.Next(q)) if (this.isEqual(q)) return true; return false; } }