public RestTemplate GetMinOfRight([FromBody] NodeDto root) { BSTree tree = new BSTree(); List <int> turnTo = new List <int>(); InterceptableNodeFactory.getInstance().setNodeInterceptor(new NodeInterceptorImpl(turnTo)); tree.setNodeFactory(InterceptableNodeFactory.getInstance()); tree.root = toEntity(root, InterceptableNodeFactory.getInstance()); int minOfRight = tree.minimumOfRightChild(); if (turnTo.Count == 0) { return(new RestTemplate((int)HttpStatusCode.Conflict, null, "This tree has no right child")); } if (turnTo.Count > 0) { turnTo.RemoveAt(turnTo.Count - 1); } turnTo.Insert(0, 1); Dictionary <string, Object> dict = new Dictionary <string, object>(); dict.Add("turnTo", turnTo); dict.Add("minOfRight", minOfRight); return(new RestTemplate((int)HttpStatusCode.OK, dict, "")); }
public RestTemplate FindX([FromBody] NodeDto root, int x) { BSTree tree = new BSTree(); List <int> turnTo = new List <int>(); InterceptableNodeFactory.getInstance().setNodeInterceptor(new NodeInterceptorImpl(turnTo)); tree.setNodeFactory(InterceptableNodeFactory.getInstance()); tree.root = toEntity(root, InterceptableNodeFactory.getInstance()); tree.findX(x); turnTo.RemoveAt(turnTo.Count - 1); Dictionary <string, Object> dict = new Dictionary <string, object>(); dict.Add("turnTo", turnTo); return(new RestTemplate((int)HttpStatusCode.OK, dict, "")); }
public RestTemplate InsertX([FromBody] NodeDto root, int x) { BSTree tree = new BSTree(); List <int> turnTo = new List <int>(); InterceptableNodeFactory.getInstance().setNodeInterceptor(new NodeInterceptorImpl(turnTo)); tree.setNodeFactory(InterceptableNodeFactory.getInstance()); tree.root = toEntity(root, InterceptableNodeFactory.getInstance()); //BSTree tree = new BSTree(toEntity(root)); try { tree.insert(x); if (turnTo.Count > 0) { if (x > turnTo[turnTo.Count - 1]) { turnTo[turnTo.Count - 1] = 1; } else { turnTo[turnTo.Count - 1] = 0; } } Dictionary <string, Object> dict = new Dictionary <string, object>(); dict.Add("turnTo", turnTo); dict.Add("tree", toDto(tree.root, 1, 0)); return(new RestTemplate((int)HttpStatusCode.OK, dict, "")); } catch (KeyAlreadyExistException ex) { return(new RestTemplate((int)HttpStatusCode.Conflict, toDto(tree.root, 1, 0), ex.Message)); } }