示例#1
0
        public IEnumerable <double> BackEnumerator()
        {
            DoublyNode <Double> current = tail;

            while (current != null)
            {
                yield return(current.Data);

                current = current.Previous;
            }
        }
示例#2
0
        IEnumerator <double> IEnumerable <double> .GetEnumerator()
        {
            DoublyNode <Double> current = head;

            while (current != null)
            {
                yield return(current.Data);

                current = current.Next;
            }
        }
示例#3
0
        public double CalcSum()
        {
            DoublyNode <Double> current = head;
            double sum = 0d;

            while (current != null)
            {
                sum    += Convert.ToDouble(current.Data);
                current = current.Next;
            }
            return(sum);
        }
示例#4
0
        public bool Contains(double data)
        {
            DoublyNode <Double> current = head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
示例#5
0
        int count;//count elements in list
        //add element
        public void Add(double data)
        {
            DoublyNode <Double> node = new DoublyNode <Double>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
示例#6
0
        public void AddFirst(double data)
        {
            DoublyNode <Double> node = new DoublyNode <Double>(data);
            DoublyNode <Double> temp = head;

            node.Next = temp;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            else
            {
                temp.Previous = node;
            }
            count++;
        }
示例#7
0
        public DoublyNode <Double> FindMaxNode()
        {
            DoublyNode <Double> current = head;
            DoublyNode <Double> max     = current;

            while (current != null)
            {
                //find last max
                if (max.Data <= current.Data)
                {
                    max = current;
                }

                current = current.Next;
            }
            return(max);
        }
示例#8
0
        public void deleteElementsBeforeMax()
        {
            DoublyNode <Double> max     = FindMaxNode();
            DoublyNode <Double> current = head;

            while (current != null)
            {
                if (current.Data != max.Data)
                {
                    Remove(current.Data);
                }
                else
                {
                    break;
                }
                current = current.Next;
            }
        }
示例#9
0
        public double CalcNumOfLessThanAvLetters()
        {
            DoublyNode <Double> current = head;
            int    counter = 0;
            double data    = 0d;
            double sum     = CalcSum();

            while (current != null)
            {
                data = Convert.ToDouble(current.Data);

                if (data.CompareTo(sum / Count) < 0)
                {
                    counter++;
                }
                current = current.Next;
            }
            return(counter);
        }
示例#10
0
        public bool Remove(double data)
        {
            DoublyNode <Double> current = head;

            //to search deleting node
            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    break;
                }
                current = current.Next;
            }
            if (current != null)
            {
                //if node is not last
                if (current.Next != null)
                {
                    current.Next.Previous = current.Previous;
                }
                else
                {
                    tail = current.Previous;
                }
                //if node is not first
                if (current.Previous != null)
                {
                    current.Previous.Next = current.Next;
                }
                else
                {
                    head = current.Next;
                }
                count--;
                return(true);
            }
            return(false);
        }
示例#11
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }