Guest User

Untitled

a guest
Feb 18th, 2020
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5.  
  6. namespace Clones
  7. {
  8. public class CloneVersionSystem : ICloneVersionSystem
  9. {
  10. List<MyClone> Clones = new List<MyClone>(){new MyClone()};
  11. public string Execute(string query)
  12. {
  13. var parameters = query.Split();
  14. var act = parameters[0];
  15. var ci = int.Parse(parameters[1]);
  16. var pi = 0;
  17. if (parameters.Length > 2)
  18. {
  19. pi = int.Parse(parameters[2]);
  20. }
  21.  
  22. switch (act)
  23. {
  24. case "learn":
  25. Clones[ci - 1].listLearned.AddLast(pi);
  26. return null;
  27. case "rollback":
  28. var tempDel = Clones[ci - 1].listLearned.Last();
  29. Clones[ci - 1].listLearned.RemoveLast();
  30. Clones[ci - 1].listRollbacked.AddLast(tempDel);
  31. return null;
  32. case "relearn":
  33. var tempRet = Clones[ci - 1].listRollbacked.Last();
  34. Clones[ci - 1].listRollbacked.RemoveLast();
  35. Clones[ci - 1].listLearned.AddLast(tempRet);
  36. return null;
  37. case "clone":
  38. Clones.Add(Clones[ci-1].Clone(Clones[ci-1]));
  39. return null;
  40. case "check":
  41. if (Clones[ci - 1].listLearned.Count == 0)
  42. {
  43. return "basic";
  44. }
  45. return Clones[ci-1].listLearned.Last().ToString();
  46. default:
  47. return null;
  48. }
  49. }
  50. }
  51.  
  52. public class MyClone
  53. {
  54. public LinkedList<int> listLearned = new LinkedList<int>();
  55. public LinkedList<int> listRollbacked = new LinkedList<int>();
  56. public MyClone Clone(MyClone oldCl)
  57. {
  58. var newCl = new MyClone();
  59. newCl.listLearned = new LinkedList<int>(oldCl.listLearned);
  60. newCl.listRollbacked = new LinkedList<int>(oldCl.listRollbacked);
  61. return newCl;
  62. }
  63. }
  64. }
RAW Paste Data