Алгоритмическое мышление при решении задач (на примере языка C#). Шамшев А.Б - 99 стр.

UptoLike

Составители: 

99
head = new ListNode(newData, head);
}
public void process() {
if (head == null) {
throw new ApplicationException("Список пуст");
}
int middle = (int)Math.Round(getMiddle());
int min = getMin();
if (head.data == min) {
head = new ListNode(middle, head);
} else {
ListNode prevNode = head;
for (; prevNode.next != null; prevNode = prevNode.next) {
if (prevNode.next.data == min) {
break;
}
}
prevNode.next = new ListNode(middle, prevNode.next);
}
}
public int getMin() {
if (head == null) {
throw new ApplicationException("Список пуст");
}
int min = head.data;
for (ListNode temp = head.next; temp != null; temp =
temp.next) {
if (temp.data < min) {
min = temp.data;
}
}
return min;
}
public double getMiddle() {
int count = 0;
double sum = 0;
for (ListNode temp = head; temp != null; temp = temp.next) {
sum += temp.data;
count++;
}
if (count == 0) {
throw new ApplicationException("Список пуст");
}
return sum / count;
}
public void print() {
for (ListNode curNode = head; curNode != null;
Console.Write(curNode.data + " "), curNode = curNode.next) ;
Console.WriteLine();
}
}
}