Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace Clones
- {
- public class Clone
- {
- public StackForClone AddProgramm;
- public StackForClone RemoveProgramm;
- public Clone()
- {
- AddProgramm = new StackForClone();
- RemoveProgramm = new StackForClone();
- }
- public Clone(Clone baseClone)
- {
- AddProgramm = new StackForClone(baseClone.AddProgramm);
- RemoveProgramm = new StackForClone(baseClone.RemoveProgramm);
- }
- }
- public class StackFCItem
- {
- public string Command;
- public StackFCItem First;
- public StackFCItem(string value, StackFCItem first)
- {
- Command = value;
- First = first;
- }
- }
- public class StackForClone
- {
- public StackFCItem Last;
- public StackForClone()
- {
- }
- public StackForClone(StackForClone baseStack)
- {
- Last = baseStack.Last;
- }
- public void Push(string item)
- {
- Last = new StackFCItem(item, Last);
- }
- public string Pop()
- {
- var result = Last.Command;
- Last = Last.First;
- return result;
- }
- }
- public class CloneVersionSystem : ICloneVersionSystem
- {
- private List<Clone> cloneslist;
- public CloneVersionSystem()
- {
- cloneslist = new List<Clone>();
- cloneslist.Add(new Clone());
- }
- public string Execute(string query)
- {
- var input = query.Split(' ');
- var command = input[0];
- var cloneIndex = int.Parse(input[1]) - 1;
- return Commands(input, cloneIndex);
- }
- public string Commands(string[] command, int num)
- {
- var clone = cloneslist[num];
- if (command[0] == "learn")
- {
- clone.AddProgramm.Push(command[2]);
- clone.RemoveProgramm.Last = null;
- }
- if (command[0] == "rollback")
- {
- if (clone.AddProgramm.Last == null)
- return null;
- var progRoll = clone.AddProgramm.Pop();
- clone.RemoveProgramm.Push(progRoll);
- }
- if (command[0] == "relearn")
- {
- if (clone.RemoveProgramm.Last == null)
- return null;
- var progRelearn = clone.RemoveProgramm.Pop();
- clone.AddProgramm.Push(progRelearn);
- }
- if (command[0] == "clone")
- {
- cloneslist.Add(new Clone(cloneslist[num]));
- }
- if(command[0] == "check")
- {
- if (clone.AddProgramm.Last == null) return "basic";
- return clone.AddProgramm.Last.Command;
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement