using CourseWork_EredavkinRA; using System.Xml.Linq; namespace CourseWorkEreda; public class ArrayManager { public StateStorage storage; private ArrayDeque? stack; public ArrayManager(ArrayDequeParameters parameters) { stack = new ArrayDeque(parameters.Number); storage = new StateStorage(); } public IEnumerable GetStates() { return storage.GetStates(); } public void ClearStates() { storage.ClearStates(); } public void SetCurrentStateToLast() { var lastState = storage.GetLastState(); if (lastState != null) { stack = new ArrayDeque(10); foreach (var item in lastState.Array) { stack.PushFront(item); } } } public StateStorage GetStorage() { return storage; } public void SetState(ArrayDequeState state) { stack.SetMemento(state); } public void FrontPush(int element) { stack.PushFront(element); ArrayDequeState state = stack.CreateMemento(); state.operation = Operation.pushFront; storage.AddState(state); state = stack.CreateMemento(); storage.AddState(stack.CreateMemento(), false); } public void BackPush(int element) { stack.PushBack(element); ArrayDequeState state = stack.CreateMemento(); state.operation = Operation.pushBack; storage.AddState(state); state = stack.CreateMemento(); storage.AddState(stack.CreateMemento(), false); } public void PopBack() { stack.PopBack(); ArrayDequeState state = stack.CreateMemento(); state.operation = Operation.popBack; storage.AddState(state); state = stack.CreateMemento(); storage.AddState(stack.CreateMemento(), false); } public void PopFront() { stack.PopFront(); ArrayDequeState state = stack.CreateMemento(); state.operation = Operation.popFront; storage.AddState(state); state = stack.CreateMemento(); storage.AddState(stack.CreateMemento(), false); } public bool IsEmpty() { return stack.IsEmpty(); } public StateStorage StepForward() { storage.StepForward(); return storage; } public StateStorage StepBackward() { storage.StepBackward(); return storage; } }