Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- namespace Clones
- {
- public class CloneVersionSystem : ICloneVersionSystem
- {
- List<MyClone> Clones = new List<MyClone>(){new MyClone()};
- public string Execute(string query)
- {
- var parameters = query.Split();
- var act = parameters[0];
- var ci = int.Parse(parameters[1]);
- var pi = 0;
- if (parameters.Length > 2)
- {
- pi = int.Parse(parameters[2]);
- }
- switch (act)
- {
- case "learn":
- Clones[ci - 1].listLearned.AddLast(pi);
- return null;
- case "rollback":
- var tempDel = Clones[ci - 1].listLearned.Last();
- Clones[ci - 1].listLearned.RemoveLast();
- Clones[ci - 1].listRollbacked.AddLast(tempDel);
- return null;
- case "relearn":
- var tempRet = Clones[ci - 1].listRollbacked.Last();
- Clones[ci - 1].listRollbacked.RemoveLast();
- Clones[ci - 1].listLearned.AddLast(tempRet);
- return null;
- case "clone":
- Clones.Add(Clones[ci-1].Clone(Clones[ci-1]));
- return null;
- case "check":
- if (Clones[ci - 1].listLearned.Count == 0)
- {
- return "basic";
- }
- return Clones[ci-1].listLearned.Last().ToString();
- default:
- return null;
- }
- }
- }
- public class MyClone
- {
- public LinkedList<int> listLearned = new LinkedList<int>();
- public LinkedList<int> listRollbacked = new LinkedList<int>();
- public MyClone Clone(MyClone oldCl)
- {
- var newCl = new MyClone();
- newCl.listLearned = new LinkedList<int>(oldCl.listLearned);
- newCl.listRollbacked = new LinkedList<int>(oldCl.listRollbacked);
- return newCl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement