public static void swap(int i, int minimum) //o(1) { nodes newnode = new nodes(); newnode = priority_queue[minimum]; //o(1) priority_queue[minimum] = priority_queue[i]; //o(1) priority_queue[i] = newnode; //o(1) }
nodes generate_Tree_for_huffman(List <nodes> list) { if (list.Count <= 1) { list[0].sympol = list[0].prob.ToString(); return(list[0]); } if (list.Count == 2) { nodes node_left = new nodes(); nodes node_right = new nodes(); node_left = list[0]; node_right = list[1]; nodes final = new nodes(); final.Left = node_left; final.Right = node_right; final.prob = node_right.prob + node_left.prob; final.sympol = final.prob.ToString(); return(final); } List <nodes> temp_lest = new List <nodes>(); temp_lest = list; nodes node_left1 = new nodes(); nodes node_right1 = new nodes(); node_left1 = list[0]; node_right1 = list[1]; nodes left_or_right = new nodes(); left_or_right.Left = node_left1; left_or_right.Right = node_right1; left_or_right.prob = node_right1.prob + node_left1.prob; left_or_right.sympol = left_or_right.prob.ToString(); temp_lest.RemoveAt(0); temp_lest.RemoveAt(0); temp_lest.Add(left_or_right); //temp_lest.Sort((x, y) => x.Item1.CompareTo(y.Item1)); temp_lest.Sort((x, y) => x.prob.CompareTo(y.prob)); nodes last_final = new nodes(); last_final = generate_Tree_for_huffman(temp_lest); return(last_final); }
public ActionResult LoadWorkFlowDesign(string keyValue) { //节点列表 var nodeData = activitybll.GetList(keyValue); //线性列表 var lineData = conditionbll.GetList(keyValue); List <nodes> nodeList = new List <nodes>(); List <lines> lineList = new List <lines>(); #region 创建nodes对象 foreach (WfTBActivityEntity entity in nodeData) { nodes nodes = new nodes(); nodes.alt = true; nodes.css = ""; nodes.id = entity.Id; //主键 nodes.img = ""; nodes.name = entity.Name; nodes.type = entity.FormName; nodes.height = entity.FormHeight.Value; nodes.left = entity.GraphLeft.Value; nodes.top = entity.Graphtop.Value; nodes.width = entity.FormWidth.Value; nodeList.Add(nodes); } #endregion #region 创建lines对象 foreach (WfTBConditionEntity entity in lineData) { lines lines = new lines(); lines.alt = true; lines.id = entity.Id; lines.from = entity.ActivityId; lines.to = entity.ToActivityId; lines.name = ""; lines.type = "sl"; lineList.Add(lines); } #endregion Flow flow = new Flow(); flow.activeID = keyValue; flow.title = "隐患流程图"; flow.initNum = 22; flow.nodes = nodeList; flow.lines = lineList; var jsonData = new { flow = flow }; return(Content(jsonData.ToJson())); }
public void reset() { myPartent = null; F = 0; G = 0; H = 0; preG = 1000000; inclosed = false; }
void MoveToNode(Vector2 d) { nodes moveToNode = CanMove(d); if (moveToNode != null) { transform.localPosition = moveToNode.transform.position; currentNode = moveToNode; } }
private void InorderTraversal(nodes t, int depth) { if (t != null) { InorderTraversal(t.Left, depth + 1); //add 1 to depth (y coordinate) t.Xpos = totalNodes++ + 1; //x coord is node number in inorder traversal t.Ypos = depth - 1; // mark y coord as depth InorderTraversal(t.Right, depth + 1); } }
/// <summary> /// Reads CS events async and then sets the datagrid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void downloader_DownloadStringCompletedCSEvents(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { string responseStream = e.Result; XmlSerializer serializer = new XmlSerializer(typeof(nodes)); fullCsEventsList.Clear(); using (TextReader reader = new StringReader(e.Result)) { try { nodes result = (nodes)serializer.Deserialize(reader); foreach (var nd in result.node) { string date = nd.startdate; Regex reg = new Regex("\\(All\\sday\\)"); if (reg.IsMatch(nd.startdate)) { date = nd.startdate.Substring(0, reg.Match(nd.startdate).Index); } DateTime startDate = DateTime.Parse(date); fullCsEventsList.Add(new VisibleCSItem() { csEventLocation = nd.location == null ? "" : Encoding.UTF8.GetString(Encoding.Default.GetBytes(nd.location)), csEventTime = startDate.Date.ToString("MMMM d, yyyy"), csEventTitle = nd.title == null ? "" : Encoding.UTF8.GetString(Encoding.Default.GetBytes(nd.title)), startDate = startDate, isEvent = true }); } } catch { } finally { if (fullCsEventsList.Count < 1) { fullCsEventsList.Add(new VisibleCSItem() { csEventTitle = "No CS Events at this time" }); } } } } fullCsEventsList.Sort((x, y) => DateTime.Compare(x.startDate, y.startDate)); //Sets the data grid Dispatcher.Invoke(() => { EventsDataGrid.DataContext = fullCsEventsList; }); }
static void Main(string[] args) { nodes <string> rootNode = BinTree(); Console.WriteLine("层次遍历方法遍历二叉树:"); LayerOrder <string>(rootNode); Console.Read(); }
private int TreeHeight(nodes t) { if (t == null) { return(-1); } else { return(1 + Math.Max(TreeHeight(t.Left), TreeHeight(t.Right))); } }
// Use this for initialization void Start() { validDirections = new Vector2[neighbours.Length]; for (int i = 0; i < neighbours.Length; i++) { nodes neighbour = neighbours[i]; Vector2 tempVector = neighbour.transform.localPosition - transform.localPosition; validDirections[i] = tempVector.normalized; } }
public void Restart() { canMove = true; currentNode = startingPosition; nextDirection = Vector2.left; transform.GetComponent <Animator>().runtimeAnimatorController = chompAnimation; transform.GetComponent <Animator>().enabled = true; ChangePosition(direction); }
public void DrawTree(nodes root, Graphics g) { try { panel1.Width = ClientSize.Width - 20; panel1.Height = ClientSize.Height - 20; int Width = panel1.Width; int Height = panel1.Height; int dx = 0, dy = 0, dx2 = 0, dy2 = 0, ys = 20; int XSCALE, YSCALE; int treeHeight = TreeHeight(root); XSCALE = (int)(Width / totalNodes); //scale x by total nodes in tree YSCALE = (int)((Height - ys) / (maxTreeHeight + 1)); //scale y by tree height if (root != null) { // inorder traversal to draw each node DrawTree(root.Left, g); // do left side of inorder traversal dx = root.Xpos * XSCALE; // get x,y coords., and scale them dy = root.Ypos * YSCALE; string s = root.sympol.ToString(); //get the word at this node s += "(" + root.prob.ToString() + ")"; g.DrawString(s, panel1.Font, blackBrush, new PointF(dx - ys, dy)); // this draws the lines from a node to its children, if any if (root.Left != null) { //draws the line to left child if it exists dx2 = root.Left.Xpos * XSCALE; dy2 = root.Left.Ypos * YSCALE; g.DrawLine(blackPen, dx, dy, dx2, dy2); } if (root.Right != null) { //draws the line to right child if it exists dx2 = root.Right.Xpos * XSCALE;//get right child x,y scaled position dy2 = root.Right.Ypos * YSCALE; g.DrawLine(blackPen, dx, dy, dx2, dy2); } DrawTree(root.Right, g); //now do right side of inorder traversal } } catch (Exception ee) { MessageBox.Show(ee.Message.ToString()); } }
nodes generate_Tree(List <Tuple <int, char> > list) { if (list.Count <= 1) { nodes ret = new nodes(); ret.Left = null; ret.Right = null; ret.sympol = list[0].Item2.ToString(); return(ret); } List <Tuple <int, char> > temp_list = new List <Tuple <int, char> >(); int all_sympol_count = 0; temp_list = list; for (int i = 0; i < temp_list.Count; i++) { all_sympol_count += temp_list[i].Item1; } List <Tuple <int, char> > right_list = new List <Tuple <int, char> >(); List <Tuple <int, char> > left_list = new List <Tuple <int, char> >(); int sum_to_hulf = 0; for (int i = 0; i < temp_list.Count; i++) { if (sum_to_hulf < all_sympol_count / 2) { right_list.Add(temp_list[i]); sum_to_hulf += temp_list[i].Item1; } else { left_list.Add(temp_list[i]); } } nodes right_node = new nodes(); nodes left_node = new nodes(); right_node = generate_Tree(right_list); left_node = generate_Tree(left_list); right_node.bit = "1"; left_node.bit = "0"; nodes nnn = new nodes(); nnn.Left = left_node; nnn.Right = right_node; return(nnn); }
nodes CanMove(Vector2 d) { nodes moveToNode = null; for (int i = 0; i < currentNode.neighbours.Length; i++) { if (currentNode.validDirections[i] == d) { moveToNode = currentNode.neighbours[i]; break; } } return(moveToNode); }
public int set_prob(nodes tree) { if (tree == null) { return(0); } else if (tree.Left == null && tree.Right == null) { tree.prob = 1; return(1); } int left = set_prob(tree.Left); int right = set_prob(tree.Right); tree.prob = left + right; the_tree = tree; return(1); }
public string calculate_bits(nodes root, string code) { if (root.Left == null && root.Right == null) { List <String> temp = new List <string>(); temp.Add(root.sympol); temp.Add(code); temp.Add(root.prob.ToString()); Encode_Bits.Add(temp); return(""); } calculate_bits(root.Left, code + "0"); calculate_bits(root.Right, code + "1"); return(""); }
void Move() { if (targetNode != currentNode && targetNode != null) { if (nextDirection == direction * -1) { direction *= -1; nodes tempNode = targetNode; targetNode = previousNode; previousNode = tempNode; } if (OverShortTarget()) { currentNode = targetNode; transform.localPosition = currentNode.transform.position; nodes MoveToNode = CanMove(nextDirection); if (MoveToNode != null) { direction = nextDirection; } if (MoveToNode == null) { MoveToNode = CanMove(direction); } if (MoveToNode != null) { targetNode = MoveToNode; previousNode = currentNode; currentNode = null; } else { direction = Vector2.zero; } } else { transform.localPosition += (Vector3)((direction) * (speed)) * Time.deltaTime; } } }
void ChangePosition(Vector2 d) { if (d != direction) { nextDirection = d; } if (currentNode != null) { nodes MoveToNode = CanMove(d); if (MoveToNode != null) { direction = d; targetNode = MoveToNode; previousNode = currentNode; currentNode = null; } } }
// Use this for initialization void Start() { audio = transform.GetComponent <AudioSource>(); nodes node = GetNodeAtPosition(transform.localPosition); startingPosition = node; if (node != null) { currentNode = node; // Debug.Log("currentNode: " + currentNode); Debug.Log(currentNode); } direction = Vector2.left; orientation = Vector2.left; ChangePosition(direction); }
public String rename_nodes(nodes tree) { if (tree == null) { return(""); } if (tree.Left == null && tree.Right == null) { return(tree.sympol); } String right_name = rename_nodes(tree.Right); String left_name = rename_nodes(tree.Left); if (tree.sympol == "#") { tree.sympol = right_name + " , " + left_name; } return(tree.sympol); }
private nodes findclosest(Vector3 pos) { nodes closestNode = new nodes(); float distance = 100000; for (int i = 0; i < Nodes.Count; i++) { float closest = Vector3.Distance(Nodes[i].position, pos); if (closest < distance) { closestNode = Nodes[i]; closestNode.myPartent = Nodes[i]; distance = closest; } } cleanNodesUp(); return(closestNode); }
public static void insert_heap(nodes node) //o(log v) { priority_queue.Add(node); int i = Count - 1; while (i > 0) { int p = (i - 1) / 2; if (priority_queue[p].time <= node.time) { break; } priority_queue[i] = priority_queue[p]; i = p; } if (Count > 0) { priority_queue[i] = node; } }
void Move() { if (targetNode != currentNode && targetNode != null && !isInGhostHouse) { if (OverShotTarget()) { currentNode = targetNode; transform.localPosition = currentNode.transform.position; targetNode = ChooseNextNode(); previousNode = currentNode; currentNode = null; UpdateAnimatorController(); } else { transform.localPosition += (Vector3)direction * moveSpeed * Time.deltaTime; } } }
public void costsetup(nodes destination, nodes parent) { nodes nodedata = destination; nodes parentnode = parent; int cost = (int)Mathf.Abs(Vector3.Distance(parentnode.getPos(), position)); if (G + cost + nodedata.G <= preG) { G = 0; G += cost; // G is based on cost from parent node to this node myPartent = parent; G += parentnode.G; // G is also the total cost from other nodes so far H = (int)Mathf.Abs(Vector3.Distance(position, nodedata.getPos())); // H is cost from this node to our destination (i have done all of the costs based on lenght calculation) F = G + H; // F = G + H preG = G; // update G for possiblity of better node } }
// Use this for initialization void Start() { backgroundAudio = GameObject.Find("Game").transform.GetComponent <AudioSource>(); pacMan = GameObject.FindGameObjectWithTag("PacMan"); nodes node = GetNodeAtPosition(transform.localPosition); if (node != null) { currentNode = node; } if (isInGhostHouse) { direction = Vector2.up; targetNode = currentNode.neighbours[0]; } /*if (isGhostHouseEntrance) * { * direction = Vector2.down; * targetNode = currentNode.neighbours[2]; * }*/ else { direction = Vector2.left; targetNode = ChooseNextNode(); } previousNode = currentNode; UpdateAnimatorController(); }
/// <summary> /// Reads the CS News, sets the card, and fades the animations /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void downloader_DownloadStringCompletedCSNews(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { string responseStream = e.Result; XmlSerializer serializer = new XmlSerializer(typeof(nodes)); using (TextReader reader = new StringReader(e.Result)) { try { nodes result = (nodes)serializer.Deserialize(reader); foreach (var nd in result.node) { string date = nd.startdate; Regex reg = new Regex("\\(All\\sday\\)"); if (reg.IsMatch(nd.startdate)) { date = nd.startdate.Substring(0, reg.Match(nd.startdate).Index); } DateTime startDate = DateTime.Parse(date); fullCsNewsList.Add(new VisibleCSItem() { csEventLocation = nd.location == null ? "" : Encoding.UTF8.GetString(Encoding.Default.GetBytes(nd.location)), csEventTime = startDate.Date.ToString("MMMM d, yyyy"), csEventTitle = nd.title == null ? "" : Encoding.UTF8.GetString(Encoding.Default.GetBytes(nd.title)), startDate = startDate, isEvent = false }); } } catch { } SetInitalCSCards(); } } }
private void downloader_DownloadStringCompletedCLAS(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { string responseStream = e.Result; clasNewsList.Clear(); try { XmlSerializer serializer = new XmlSerializer(typeof(nodes)); using (TextReader reader = new StringReader(e.Result)) { //reader.Namespaces = false; nodes result = (nodes)serializer.Deserialize(reader); foreach (var nd in result.node) { clasNewsList.Add(new VisibleNewsItem() { NewsTitle = nd.title == null ? "" : Encoding.UTF8.GetString(Encoding.Default.GetBytes(nd.title)), }); } } } catch { } finally { if (clasNewsList.Count < 1) { clasNewsList.Add(new VisibleNewsItem() { NewsTitle = "No CLAS news at this time" }); } } } }
static nodes <string> BinTree() { nodes <string>[] binTree = new nodes <string> [8]; //创建结点 binTree[0] = new nodes <string>("A"); binTree[1] = new nodes <string>("B"); binTree[2] = new nodes <string>("C"); binTree[3] = new nodes <string>("D"); binTree[4] = new nodes <string>("E"); binTree[5] = new nodes <string>("F"); binTree[6] = new nodes <string>("G"); binTree[7] = new nodes <string>("H"); //使用层次遍历二叉树的思想,构造一个已知的二叉树 binTree[0].LNode = binTree[1]; binTree[0].RNode = binTree[2]; binTree[1].RNode = binTree[3]; binTree[2].LNode = binTree[4]; binTree[2].RNode = binTree[5]; binTree[3].LNode = binTree[6]; binTree[3].RNode = binTree[7]; //返回二叉树的根结点 return(binTree[0]); }
public Form1() { InitializeComponent(); readfolder(@"C:\Users\Lenovo\Desktop\[2] Medium Cases"); int size_list = files.Count / 3; for (int i = 0; i < size_list; i++) //exact n , n:num of files { dic_edges.Clear(); //o(1) list_query.Clear(); //o(1) //list_vertix.Clear(); //o(1) nodes[] vertix = readfile(files[i], files[i + (2 * size_list)], files[i + size_list]); dic_temp.Clear(); //o(1) foreach (KeyValuePair <Int32, List <KeyValuePair <Int32, info> > > node in dic_edges) //o(e) , e = num of edges { Int32 key = node.Key; List <KeyValuePair <Int32, info> > lis = new List <KeyValuePair <Int32, info> >(); for (int c = 0; c < node.Value.Count; c++) { Int32 end_ = node.Value[c].Key; //o(1) info temp = new info(); //o(1) temp.distance = node.Value[c].Value.distance; //o(1) temp.speed = node.Value[c].Value.speed; //o(1) temp.time = node.Value[c].Value.time; //o(1) lis.Add(new KeyValuePair <Int32, info>(end_, temp)); //o(1) } dic_temp.Add(key, lis); //o(1) } priorityqueue.getdata(prority_queue, dic_edges, list_query); //o(1) Stopwatch sw1 = new Stopwatch(); sw1.Start(); for (int j = 0; j < list_query.Count; j++) { prority_queue.Clear(); //kda kda hy3ml over write 3lah for (Int32 k = 0; k < vertix.Count(); k++) //o(v) , v: num of vertix { nodes p = new nodes(); //o(1) p.name = vertix[k].name; //o(1) p.parent = vertix[k].parent; //o(1) p.x = vertix[k].x; //o(1) p.y = vertix[k].y; //o(1) p.time = vertix[k].time; //o(1) p.distance = vertix[k].distance; //o(1) p.visited = vertix[k].visited; //o(1) prority_queue.Add(p); //o(1) //prority_queue[list_vertix[k].name] = p; } priorityqueue.getdata(prority_queue, dic_temp, list_query); //o(1) priorityqueue.shortestpath(list_query[j].xstart, list_query[j].ystart, list_query[j].xend, list_query[j].yend, list_query[j].radius, i + 1); } sw1.Stop(); //o(1) Console.WriteLine(sw1.ElapsedMilliseconds); } }
public static nodes[] readfile(string map, string query, string output) { FileStream file = new FileStream(@map, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(file); int vertices; //int wronganswers = 0; int edges; string line = sr.ReadLine(); vertices = int.Parse(line); nodes[] list_vertix = new nodes[vertices]; //prority_queue.Add(dummy); for (int i = 0; i < vertices; i++) { line = sr.ReadLine(); string[] lineparts = line.Split(' '); nodes n = new nodes(); n.name = Int32.Parse(lineparts[0]); n.distance = double.MaxValue; n.time = double.MaxValue; n.parent = -4; n.visited = false; n.x = double.Parse(lineparts[1]); n.y = double.Parse(lineparts[2]); //prority_queue.Add(n); //list_vertix.Add(n);t3del list_vertix[n.name] = n; } //dictionary of edges line = sr.ReadLine(); edges = int.Parse(line); for (int i = 0; i < edges; i++)//e { line = sr.ReadLine(); string[] lineparts = line.Split(' '); info edge = new info(); Int32 key_ = Int32.Parse(lineparts[0]); Int32 end = Int32.Parse(lineparts[1]); edge.distance = double.Parse(lineparts[2]); edge.speed = double.Parse(lineparts[3]); edge.time = (edge.distance / edge.speed) * 60; // time minutes if (dic_edges.ContainsKey(key_) == true) { List <KeyValuePair <Int32, info> > old_list = new List <KeyValuePair <Int32, info> >(); dic_edges.TryGetValue(key_, out old_list); // return bool (true or false) (true return value) old_list.Add(new KeyValuePair <Int32, info>(end, edge)); dic_edges[key_] = old_list; } else { List <KeyValuePair <Int32, info> > old_list = new List <KeyValuePair <Int32, info> >(); old_list.Add(new KeyValuePair <Int32, info>(end, edge)); dic_edges.Add(key_, old_list); } //______________________// // bnzbt mn al end ll start if (dic_edges.ContainsKey(end) == true) { List <KeyValuePair <Int32, info> > old_list = new List <KeyValuePair <Int32, info> >(); dic_edges.TryGetValue(end, out old_list); // return bool (true or false) (true return value) old_list.Add(new KeyValuePair <Int32, info>(key_, edge)); dic_edges[end] = old_list; } else { List <KeyValuePair <Int32, info> > old_list = new List <KeyValuePair <Int32, info> >(); old_list.Add(new KeyValuePair <Int32, info>(key_, edge)); dic_edges.Add(end, old_list); } } sr.Close(); //_____________________________________________________________// FileStream file1 = new FileStream(@query, FileMode.Open, FileAccess.Read); StreamReader sr1 = new StreamReader(file1); int num_queries; line = sr1.ReadLine(); num_queries = int.Parse(line); for (int i = 0; i < num_queries; i++) { line = sr1.ReadLine(); string[] lineparts = line.Split(' '); query quer = new query(); quer.xstart = double.Parse(lineparts[0]); quer.ystart = double.Parse(lineparts[1]); quer.xend = double.Parse(lineparts[2]); quer.yend = double.Parse(lineparts[3]); quer.radius = double.Parse(lineparts[4]); list_query.Add(quer); } sr1.Close(); return(list_vertix);//t3deel }
public override void Visit(nodes.ConditionNode node) { NextNode = node.Next; }
public void Delete(nodes.ListNode listNode) { throw new System.NotImplementedException(); }