Ejemplo n.º 1
0
        /// 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++;
        }
Ejemplo n.º 2
0
        /// 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++;
        }
Ejemplo n.º 3
0
        /// Removes an object
        public void Remove(Object n)
        {
            CircularlyNode p = FindPrevious(n);

            if (!(p.Flink == null))
            {
                p.Flink = p.Flink.Flink;
            }
            count--;
        }
Ejemplo n.º 4
0
        /// 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);
        }
Ejemplo n.º 5
0
        /// 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);
        }
Ejemplo n.º 6
0
        /// 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;
            }
        }
Ejemplo n.º 7
0
        /// 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);
        }
Ejemplo n.º 8
0
 /// Constructor for the CircularlyNode accepting an object
 public CircularlyNode(Object theElement)
 {
     Element = theElement;
     Flink   = null;
     Blink   = null;
 }
Ejemplo n.º 9
0
 /// Constructor for the CircularlyNode
 public CircularlyNode()
 {
     Element = null;
     Flink   = null;
     Blink   = null;
 }
Ejemplo n.º 10
0
 /// Constructor for CircularlyLinkedList
 public CircularlyLinkedList()
 {
     count        = 0;
     header       = new CircularlyNode("header");
     header.Flink = header;
 }