private void button7_Click(object sender, EventArgs e) { //Construct a binary tree as the given example ////////////4///////// ///////2 ////////5/// ////1////3/////////6 //0//////////////////// //Expected output as a doubly linked list 0,1,2,3,4,5,6 //BiNode root = new BiNode(4); //root.Node1 = new BiNode(2); //root.Node2 = new BiNode(5); //root.Node1.Node1 = new BiNode(1); //root.Node1.Node2 = new BiNode(3); //root.Node2.Node1 = null; //root.Node2.Node2 = new BiNode(6); //root.Node1.Node1.Node1 = new BiNode(0); //test case as in the picture BiNode root = new BiNode(1); root.Node1 = new BiNode(2); root.Node2 = new BiNode(3); root.Node1.Node1 = new BiNode(4); root.Node1.Node2 = new BiNode(5); root.Node2.Node1 = new BiNode(6); root.Node2.Node2 = new BiNode(7); BinaryTreeToLinkedList obj = new BinaryTreeToLinkedList(); string output = obj.ConvertWithoutUsingAdditionDataStructure(root); this.textBox6.Text = output; }
public BiNode() { this.data = default(T); this.leftChild = null; this.rightChild = null; }
public BiNode(T data) { this.data = data; this.leftChild = null; this.rightChild = null; }
public BiNode(BiNode <T> leftBiNode, BiNode <T> rightBiNode) { this.data = default(T); this.leftChild = leftBiNode; this.rightChild = rightBiNode; }
public BiNode(T data, BiNode <T> leftBiNode, BiNode <T> rightBiNode) { this.data = data; this.leftChild = leftBiNode; this.rightChild = rightBiNode; }
private void TryToLoadBiTree() { List <BiNode> biNodeList = new List <BiNode>(); string biTreeFilePath = FileMg.AutoRDataFileDir + Constants.ROutputFileName; if (File.Exists(biTreeFilePath)) { StreamReader sr = new StreamReader(biTreeFilePath); while (!sr.EndOfStream) { string line = sr.ReadLine().Trim(); string[] attrs = line.Split(' '); if (attrs.Length >= 2) { BiNode leftNode = new BiNode(); BiNode rightNode = new BiNode(); BiNode curNode = new BiNode(); string leftValue = attrs[0]; string rightValue = attrs[attrs.Length - 1]; if (leftValue.StartsWith("-")) { leftNode.Left = null; leftNode.Right = null; leftNode.Value = Int32.Parse(leftValue.Substring(1)); } else { int pos = Int32.Parse(leftValue); leftNode = biNodeList[pos - 1]; } if (rightValue.StartsWith("-")) { rightNode.Left = null; rightNode.Right = null; rightNode.Value = Int32.Parse(rightValue.Substring(1)); } else { int pos = Int32.Parse(rightValue); rightNode = biNodeList[pos - 1]; } curNode.Left = leftNode; curNode.Right = rightNode; curNode.Value = -1; biNodeList.Add(curNode); } } sr.Close(); } if (biNodeList.Count > 0) { mBiTreeRoot = biNodeList[biNodeList.Count - 1]; } }
private void Concat(BiNode x, BiNode y) { x.Node2 = y; y.Node1 = x; }