/* * POSITION_DLL.java * * Created on February 6, 2008, 1:51 PM * * * MORE UP TO DATE VERSION IS IN LIST_DLL_purge with classname POSITION * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package list_dll_purge; /** * * @author suchenek */ //Copyright Dr. Marek A. Suchenek, 2005, 2006, 2007, 2008 ,2009, 2010, 2011 - 2025 // Interpretation: Always points to the previous element (for an extra level of indirection); // needed to accomodate "end" position (next after last). // 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 header // ensures the existence of first position.) // Definition of nose for a non-empty subtail N of list L: the inverse function of tail, that is, // nose of tail of N is identical with N // Property: nose of subtail N of list L is position of the head of N in L. // 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 public class POSITION_DLL { public Object head; public POSITION_DLL tail; public POSITION_DLL nose; public boolean isEqual(POSITION_DLL p) { return (this == p); // test (this.tail == p.tail) doesn't work // for this and p being end positions on // different lists (returns true, while false // is correct) } public boolean isValidPosition(LIST_DLL L) { if (this.isEqual(L.End())) return true; for (POSITION_DLL q = L.First(); q != L.End(); q = L.Next(q)) if (this.isEqual(q)) return true; return false; } }