/// Inserts a new CircularlyNode at the first position public void InsertFirst(Object n) { CircularlyNode current = new CircularlyNode(n); current.Flink = header; header.Flink = current; count++; }
/// Inserts the object after the specified object public void Insert(Object n1, Object n2) { CircularlyNode current = new CircularlyNode(); CircularlyNode newnode = new CircularlyNode(n1); current = Find(n2); newnode.Flink = current.Flink; current.Flink = newnode; count++; }
/// Removes an object public void Remove(Object n) { CircularlyNode p = FindPrevious(n); if (!(p.Flink == null)) { p.Flink = p.Flink.Flink; } count--; }
/// Finds the previous CircularlyNode and returns this private CircularlyNode FindPrevious(Object n) { CircularlyNode current = header; while (!(current.Flink == null) && current.Flink.Element != n) { current = current.Flink; } return(current); }
/// Finds an object in the list and returns the CircularlyNode private CircularlyNode Find(Object n) { CircularlyNode current = new CircularlyNode(); current = header.Flink; while (current.Element != n) { current = current.Flink; } return(current); }
/// Prints the list to the Console public void PrintList() { CircularlyNode current = new CircularlyNode(); current = header; while (!(current.Flink.Element.ToString() == "header")) { Console.WriteLine(current.Flink.Element); current = current.Flink; } }
/// Moves the CircularlyNode at the specified index public CircularlyNode Move(int n) { CircularlyNode current = header.Flink; CircularlyNode temp; for (int i = 0; i <= n; i++) { current = current.Flink; } if (current.Element.ToString() == "header") { current = current.Flink; } temp = current; return(temp); }
/// Constructor for the CircularlyNode accepting an object public CircularlyNode(Object theElement) { Element = theElement; Flink = null; Blink = null; }
/// Constructor for the CircularlyNode public CircularlyNode() { Element = null; Flink = null; Blink = null; }
/// Constructor for CircularlyLinkedList public CircularlyLinkedList() { count = 0; header = new CircularlyNode("header"); header.Flink = header; }