Beispiel #1
0
        public RingElement PopRandom()
        {
            Random      random      = new Random();
            int         randomIndex = random.Next(0, this.length + 1);
            RingElement element     = this.tail;

            for (int i = 0; i < randomIndex; i++)
            {
                element = element.GetNext();
            }

            this.Delete(element);

            return(element);
        }
Beispiel #2
0
        public void Delete(RingElement element)
        {
            if (this.length > 0)
            {
                RingElement current = this.tail.GetNext();

                for (int i = 0; i < this.length; i++)
                {
                    if (current.GetNext().Equals(element))
                    {
                        current.SetNext(current.GetNext().GetNext());
                    }

                    current = current.GetNext();
                }

                this.length--;
            }
        }
Beispiel #3
0
        public void Print()
        {
            if (this.length > 0)
            {
                RingElement currentElement = this.tail.GetNext();

                Console.Write("\n");

                do
                {
                    Console.Write(" " + currentElement.ToString() + " ");

                    currentElement = currentElement.GetNext();
                } while (!currentElement.Equals(this.tail.GetNext()));

                Console.Write("\n");

                Console.WriteLine("Tail: " + this.tail);
            }
        }
Beispiel #4
0
        public RingElement Append(int value)
        {
            RingElement element = new RingElement(value);

            if (this.length == 0)
            {
                this.tail = element;
                this.tail.SetNext(this.tail);
            }
            else
            {
                element.SetNext(this.tail.GetNext());
                this.tail.SetNext(element);

                this.tail = element;
            }

            this.length++;

            return(element);
        }
Beispiel #5
0
 public void SetNext(RingElement element)
 {
     this.next = element;
 }
Beispiel #6
0
 public RingElement Search(RingElement element)
 {
     return(null);
 }