Exemplo n.º 1
0
        public void Remove(T Delete)
        {
            CircularNode <T> traversalNode = Head;


            bool Found = Contains(Delete);

            if (Found)
            {
                if (Delete.Equals(Head.Data))
                {
                    Head = Head.NextNode;
                    Head.PreviousNode = Tail;
                }
                else if (Delete.Equals(Tail.Data))
                {
                    CircularNode <T> NewTail = Tail.PreviousNode;
                    Tail              = null;
                    Tail              = NewTail;
                    NewTail           = null;
                    Head.PreviousNode = Tail;
                    Tail.NextNode     = Head;
                }
                else
                {
                    traversalNode = null;
                    traversalNode = traversalNode.NextNode;
                }
            }
        }
Exemplo n.º 2
0
        public void Print()
        {
            CircularNode <T> traversalNode = Head;

            while (traversalNode != Tail)
            {
                Console.WriteLine(traversalNode.Data);
                traversalNode = traversalNode.NextNode;
            }
            Console.WriteLine(Tail.Data);
            Console.WriteLine(" ");
        }
Exemplo n.º 3
0
 public void Add(T value)
 {
     if (Head == null)
     {
         Head = new CircularNode <T>(value);
         Tail = Head;
     }
     else
     {
         CircularNode <T> TraversalNode = Tail;
         TraversalNode.NextNode = new CircularNode <T>(value);
         Head.PreviousNode      = TraversalNode.NextNode;
         Tail = TraversalNode.NextNode;
         Tail.PreviousNode = TraversalNode;
         Tail.NextNode     = Head;
     }
 }
Exemplo n.º 4
0
        public bool Contains(T value)
        {
            CircularNode <T> traversalNode = Head;

            while (traversalNode != null)
            {
                if (value.CompareTo(traversalNode.Data) == 0)
                {
                    return(true);
                }
                else
                {
                    traversalNode = traversalNode.NextNode;
                }
            }

            Console.WriteLine("Unable to Locate Character Selected");
            return(false);
        }
Exemplo n.º 5
0
        public IEnumerable <CircularNode <T> > Nodes()
        {
            CircularNode <T> temp = Head;

            if (temp == null)
            {
                yield break;
            }
            yield return(temp);

            temp = temp.NextNode;

            while (temp != null && temp != Head)
            {
                yield return(temp);

                temp = temp.NextNode;
            }
        }
Exemplo n.º 6
0
 public CircularNode(T data)
 {
     Data         = data;
     NextNode     = null;
     PreviousNode = null;
 }
Exemplo n.º 7
0
 public CircularLinkedList()
 {
     Head = null;
 }