Програма за провеждане на държавен изпит за придобиване на втора степен на професионална квалификация за специалност



Pdf просмотр
страница11/38
Дата27.09.2022
Размер2.08 Mb.
#115149
ТипПрограма
1   ...   7   8   9   10   11   12   13   14   ...   38
Изпитни теми

DynamicList.cs

public class DynamicList { private Node head; private Node tail; private int count; public int Count { get { return this.count;
} private set { this.count = value;
}
} public DynamicList() { this.head = null; this.tail = null; this.count = 0;
} public void Add(object item) { if (this.head == null) {
Node next = new Node(item); this.head = next; this.tail = next;
} else {
Node next = new Node(item, tail); this.tail = next;
} this.count++;
} public int IndexOf(object item) {
Node current = head; int index = 0; while (current != null) { if (current.Element.Equals(item)) return index; index++; current = current.Next;
} return -1; // Not Found
} public object Remove(int index) {
Object item = null;
Node current = head;
Node previous = null; int i = 0; while (current != null) { if (index == i) { item = current.Element; previous.Next = current.Next; break;


} i++; previous = current; current = current.Next;
} return item;
} public int Remove(object item) { int index = 0;
Node current = head; while (current != null) { if (current.Element.Equals(item)) {
Remove(index); return index;
} index++; current = current.Next;
} return -1; // Not Found
} public object this[int index] { get {
Node current = head; int i = 0; while (current != null) { if (i == index) return current.Element; i++; current = current.Next;
} return null; // Not Found
} set {
Node current = head; int i = 0; while (current != null) { if (i == index) { current.Element = value; break;
} i++; current = current.Next;
}
}
}
}







Сподели с приятели:
1   ...   7   8   9   10   11   12   13   14   ...   38




©obuch.info 2024
отнасят до администрацията

    Начална страница