public IEnumerable <double> BackEnumerator() { DoublyNode <Double> current = tail; while (current != null) { yield return(current.Data); current = current.Previous; } }
IEnumerator <double> IEnumerable <double> .GetEnumerator() { DoublyNode <Double> current = head; while (current != null) { yield return(current.Data); current = current.Next; } }
public double CalcSum() { DoublyNode <Double> current = head; double sum = 0d; while (current != null) { sum += Convert.ToDouble(current.Data); current = current.Next; } return(sum); }
public bool Contains(double data) { DoublyNode <Double> current = head; while (current != null) { if (current.Data.Equals(data)) { return(true); } current = current.Next; } return(false); }
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++; }
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++; }
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); }
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; } }
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); }
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); }
public void Clear() { head = null; tail = null; count = 0; }