using CourseWork_EredavkinRA; using System; namespace CourseWork_EredavkinRA; public class ArrayDeque { public int[] array; public int Count; public int maxCount = 10; private int top; public ArrayDeque(int size) { array = new int[size]; top = -1; } public void PushBack(int element) { if (top >= array.Length - 1) { MessageBox.Show("Дек переполнен. Невозможно добавить элемент."); return; } top++; array[top] = element; } public int PopBack() { if (top == -1) { MessageBox.Show("Дек пуст. Отсутствует элемент для удаления."); return -1; } int poppedElement = array[top]; array[top] = 0; top--; return poppedElement; } public void PushFront(int element) { for (int i = top; i >= 0; i--) { array[i + 1] = array[i]; } array[0] = element; top++; } public int PopFront() { if (top == -1) { MessageBox.Show("Дек пуст. Отсутствует элемент для удаления."); return -1; } int poppedElement = array[0]; for (int i = 0; i < top; i++) { array[i] = array[i + 1]; } array[top] = 0; top--; return poppedElement; } public bool IsEmpty() { return top == -1; } public int[] GetArray() { return array; } public ArrayDequeState CreateMemento() { return new ArrayDequeState((int[])array.Clone(), top); } public ArrayDequeState GetState(ArrayDequeParameters parameter) { return new ArrayDequeState(array, Count); } public bool InBound(int index) { return index >= 0 && index < maxCount; } public void SetMemento(ArrayDequeState memento) { array = (int[])memento.Array.Clone(); top = memento.Top; } }