/// Inserts a new object after the specified object public void Insert(Object newItem, Object after) { LinkedNode current = new LinkedNode(); LinkedNode newLinkedNode = new LinkedNode(newItem); current = Find(after); newLinkedNode.Link = current.Link; current.Link = newLinkedNode; }
/// Removes an object public void Remove(Object n) { LinkedNode p = FindPrevious(n); if (!(p.Link == null)) { p.Link = p.Link.Link; } }
/// Finds the previous LinkedNode and returns this private LinkedNode FindPrevious(Object n) { LinkedNode current = header; while (!(current.Link == null) && (current.Link.Element != n)) { current = current.Link; } return(current); }
/// Prints the LinkedList to Console public void PrintList() { LinkedNode current = new LinkedNode(); current = header; while (!(current.Link == null)) { Console.WriteLine(current.Link.Element); current = current.Link; } }
/// Finds an object in the LinkedList and returns the LinkedNode public LinkedNode Find(Object item) { LinkedNode current = new LinkedNode(); current = header; while (header != item) { current = current.Link; } return(current); }
/// Resets the iterator public void Reset() { current = theList.getFirst(); previous = null; }
/// Inserts an object before public void InsertBefore(Object theElement) { LinkedNode newNode = new LinkedNode(theElement); }
/// Moves the iterator to the next link public void NextLink() { previous = current; current = current.Link; }
/// Constructor for the ListIter public ListIter(LinkedList list) { theList = list; current = theList.getFirst(); previous = null; }
/// Constructor for LinkedNode accepting an object public LinkedNode(Object theElement) { Element = theElement; Link = null; }
/// Constructor for LinkedNode public LinkedNode() { Element = null; Link = null; }
/// Constructor for LinkedList public LinkedList() { header = new LinkedNode("header"); }