клоны тупые

← разместить еще код

памагите

Расшаренный код:

using System;
using System.Collections.Generic;

namespace Clones
{
	public class CloneVersionSystem : ICloneVersionSystem
	{
        public StackOfItems<string> Programs;
        public StackOfItems<string> Cancels;

        private readonly List<Clone> listOfClones = new List<Clone>();
        private string[] commandsArray;
        private int index;
        string command;
        public string Execute(string query)
		{
            commandsArray = query.Split(' ');
            index = Convert.ToInt32(commandsArray[1]) - 1;
            command = commandsArray[0];

            if (listOfClones.Count == 0) listOfClones.Add(new Clone());

            switch (command)
            {
                case "clone":
                    listOfClones.Add(new Clone(listOfClones[index]));
                    break;
                case "learn":
                    listOfClones[index].Learn(commandsArray[2]);
                    break;
                case "relearn":
                    listOfClones[index].Relearn();
                    break;
                case "rollback":
                    listOfClones[index].Rollback();
                    break;
                case "check":
                    return listOfClones[index].Check();
            }
            return null;
        }
	}

    public class Items<T>
    {
        public Items<T> Next { get; set; }
        public Items<T> Previous { get; set; }
        public T Value { get; set; }
    }

    public class StackOfItems<T>
    {
        public Items<T> Head;
        public Items<T> Tail;

        public void Push(T item)
        {
            if (Head != null)
            {
                Items<T> newItem = new Items<T>
                { Next = null, Previous = Tail, Value = item };
                Tail.Next = Tail = newItem;
            }
            else Tail = Head = new Items<T>
            { Next = null, Previous = null, Value = item };
        }

        public T Pop()
        {
            if (Tail == null) return default;
            T value = Tail.Value;
            Tail = Tail.Previous;
            if (Tail == null)
                Head = null;
            else
                Tail.Next = null;
            return value;
        }
    }
    public class Clone
    {
        public StackOfItems<string> Cancels;
        public StackOfItems<string> Programs;

        public Clone()
        {
            Cancels = new StackOfItems<string>();
            Programs = new StackOfItems<string>();
        }

        public Clone(Clone clonedItem)
        {
            Cancels = new StackOfItems<string>()
            { Head = clonedItem.Cancels.Head, Tail = clonedItem.Cancels.Tail };
            Programs = new StackOfItems<string>()
            { Head = clonedItem.Programs.Head, Tail = clonedItem.Programs.Tail };
        }

        public void Learn(string program)
        {
            Programs.Push(program);
            Cancels = new StackOfItems<string>();
        }

        public void Relearn()
        {
            Programs.Push(Cancels.Pop());
        }

        public void Rollback()
        {
            Cancels.Push(Programs.Pop());
        }

        public string Check()
        {
            if (Programs.Head == null)
                return "basic";
            else
            {
                string result = Programs.Pop();
                Programs.Pop();
                Programs.Push(result);
                return result;
            }
        }
    }
}